JSFiddle - React, Tailwind, and code Playground
JavaScript
// Let's not pollute the global namespace.
(function(){
// The constructor:
function test() {
// Must copy arguments, since they're read only
this.args = [];
this.addArgs(arguments);
}
// Add some methods:
test.prototype = {
example : function() {
// Add on new arguments
this.addArgs(arguments);
// Return the instance for chainability
return this;
},
showAll : function() {
var i, string = "The params are: ";
// Add on new arguments
this.addArgs(arguments);
// show all arguments
alert(string + this.args.join(", "));
return this;
},
addArgs: function(array) {
var i;
for (i = 0; i < array.length; ++i)
{ this.args.push(array[i]); }
return this;
}
};
new test("p1", "p2").example("p3").example("p4", "p5").showAll("p6", "p7", "p8");
})();