The fact is that the function must be evaluated using the "parent" function. For example,
foo().bar().test();
must evaluate:
foo().test();
so you can call another function on foo() . For this you can return this :
function foo() { // empty, nothing interesting here } foo.prototype.bar = function() { return this; } foo.prototype.test = function() { return this; }
Then
var something = new foo(); something.bar() === something;
Because of this:
something.bar().test() === something.test(); // true
Since something.bar() evaluates to something , you can immediately call the second function at a time.
pimvdb Sep 19 '11 at 18:13 2011-09-19 18:13
source share