I am wondering if the code beneath considered as the proper way to achieve the topics stated in the title of the post.
I wonder is the best practice for achieving it?
var Obj = function() {
if (arguments.length) {
//do something
for (var i in arguments) //iterate over the arguments
alert(arguments[i]);
}
};
Obj.prototype.foo = function() {
alert("foo");
return this;
};
Obj.prototype.bar = function() {
alert("bar");
return this;
};
Obj.spam = function() {
alert("spam");
};
//varargs constructor
var varargs = ["arg1", "arg2"];
new Obj();
new Obj(varargs);
new Obj("a", "b", 1, 2.5);
//method chaining
new Obj().foo().bar();
//static method
Obj.spam();
arguments
from within the function? – Jay Oct 20 '12 at 9:30