, ,
... , , , , JavaScript. JavaScript , !
, , , , , , object.method, function.bind.
, ?
? - Java , Python: , , , , . JavaScript, .
this , :
var Thing= makeClass();
Thing.prototype.init= function(a) {
this._a= a;
this.showA= this.showA.bind(this);
};
Thing.prototype.showA= function() {
alert(this._a);
};
thing= new Thing(3);
setTimeout(thing.showA, 1000);
(function.bind - JavaScript, Function.prototype, .)
, , , , , , , , , .
, this. , , . , :
var User= makeClass();
User.prototype.init= function(first, last){
this.name= first+' '+last;
this.method2= this._method2factory();
};
User.prototype._method2factory= function() {
var _v2= 0;
function inc() {
_v2++;
}
return function method2(a,b,c) {
inc();
WScript.echo('doOtherWork('+this.name+') v2= '+_v2);
return _v2;
};
};
, , this._v2 this._inc().