instance.replaceMe( 40 ).revealVar(); warnings 42
OK, that return MyClass.staticHelper(this, value);’s enough for that . The only question is whether the next call should instance.revealVar()now warn 2 or 42 - if you want it to instancebe changed to 42, it becomes more complicated:
this = MyClass.staticHelper( value );
... this , ThisBinding , , - , .
, .
, , instance ( ), instance revealVar() 2.
?
, . - call () , new :
MyClass.call( instance, instance.myVar + value );
, . , replaceMe this, replaceMe.
, , , :
….replaceMe = function(val) {
var newInst = MyClass.staticHelper(this, val);
for (var prop in newInst)
if (newInst.hasOwnProperty(prop))
this[prop] = newInst[prop];
return this;
};
, , .
Btw, , .