Note that self = this is kind of a legacy hack for binding 'this'.
ES5 has Function.bind
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
ES5 has Function.bind
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
var Person = function(name) {
var self = this;
self.name = name
};
Person.prototype = new function() {
var prototype = this;
prototype.sayHello = function() {
var self = this;
return "Hello\n\n-- " + self.name;
};
};
var me = new Person('Peter');
console.log(me.sayHello());
Obviously that's a pretty contrived example but it illustrates the idea. It makes it really clear exactly what "this" means at different points in your code. As a bonus, if I had to reference the current context inside of a prototype method, "this" is now available.On that basis, if you must do this, I would suggest `var _this`, `var scope` (though that would probably be confusing if you had the misfortune to be using Angular), `var me` (unless you happen to find anthropomorphism distasteful) or... well, anything other than `var self`, really.