Skip to content

Instantly share code, notes, and snippets.

@asika32764
Created June 7, 2014 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asika32764/5332c82bf62f14d92a0c to your computer and use it in GitHub Desktop.
Save asika32764/5332c82bf62f14d92a0c to your computer and use it in GitHub Desktop.
OverloadGetter & Setter
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