Created
June 7, 2014 17:05
-
-
Save asika32764/5332c82bf62f14d92a0c to your computer and use it in GitHub Desktop.
OverloadGetter & Setter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.overloadSetter = function(usePlural) | |
{ | |
var self = this; | |
return function(a, b) | |
{ | |
if (a == null) | |
{ | |
return this; | |
} | |
if (usePlural || typeof a != 'string') | |
{ | |
for (var k in a) s | |
{ | |
elf.call(this, k, a[k]); | |
} | |
if (enumerables) | |
{ | |
for (var i = enumerables.length; i--;) | |
{ | |
k = enumerables[i]; | |
if (a.hasOwnProperty(k)) | |
{ | |
self.call(this, k, a[k]); | |
} | |
} | |
} | |
} | |
else | |
{ | |
self.call(this, a, b); | |
} | |
return this; | |
}; | |
}; | |
Function.prototype.overloadGetter = function(usePlural) | |
{ | |
var self = this; | |
return function(a) | |
{ | |
var args, result; | |
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]); | |
} | |
} | |
else | |
{ | |
result = self.call(this, a); | |
} | |
return result; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment