Permalink
Browse files

Fixes Function.prototype.overloadGetter(usePlural), when it's called …

…as getter('aa').
  • Loading branch information...
1 parent 8d26bd4 commit 14512ff86254099cf1f7a88b6172e5c6cb34f68f @arian arian committed Feb 9, 2012
Showing with 18 additions and 16 deletions.
  1. +2 −1 Source/Core/Core.js
  2. +16 −15 Specs/1.3base/Core/Core.js
View
@@ -86,8 +86,9 @@ Function.prototype.overloadGetter = function(usePlural){
var self = this;
return function(a){
var args, result;
- if (usePlural || typeof a != 'string') args = a;
+ if (typeof a != 'string') args = a;
else if (arguments.length > 1) args = arguments;
+ else if (usePlural) args = [a];
if (args){
result = {};
for (var i = 0; i < args.length; i++) result[args[i]] = self.call(this, args[i]);
View
@@ -67,9 +67,9 @@ describe('Function.prototype.overloadGetter', function(){
var object, getter;
beforeEach(function(){
object = {
- a: 1,
- b: 2,
- c: 3
+ aa: 1,
+ bb: 2,
+ cc: 3
};
getter = (function(key){
@@ -80,27 +80,28 @@ describe('Function.prototype.overloadGetter', function(){
it('should call a getter for each argument', function(){
getter = getter.overloadGetter();
- expect(getter('a')).toEqual(1);
- expect(getter('b')).toEqual(2);
- expect(getter('c')).toEqual(3);
- expect(getter('d')).toBeNull();
+ expect(getter('aa')).toEqual(1);
+ expect(getter('bb')).toEqual(2);
+ expect(getter('cc')).toEqual(3);
+ expect(getter('dd')).toBeNull();
- expect(getter('a', 'b', 'c')).toEqual(object);
- expect(getter(['a', 'b', 'c'])).toEqual(object);
- expect(getter(['a', 'c', 'd'])).toEqual({a: 1, c: 3, d: null});
+ expect(getter('aa', 'bb', 'cc')).toEqual(object);
+ expect(getter(['aa', 'bb', 'cc'])).toEqual(object);
+ expect(getter(['aa', 'cc', 'dd'])).toEqual({aa: 1, cc: 3, dd: null});
});
it('should work in plural mode', function(){
getter = getter.overloadGetter(true);
- expect(getter('a')).toEqual({
- a: 1
+ expect(getter('aa')).toEqual({
+ aa: 1
});
- expect(getter(['a', 'b'])).toEqual({
- a: 1,
- b: 2
+ expect(getter(['aa', 'bb'])).toEqual({
+ aa: 1,
+ bb: 2
});
+
})
});

0 comments on commit 14512ff

Please sign in to comment.