In Javascript this is bound to the current function so when you want to keep a reference to an "outer" object you see the pattern:
var self = this;
as in:
var self = this;
return function(whatever) {
return self.foo(whatever); // `this` here is for the inner function
}- Is var self = this; a bad pattern?
- Do what feels right
- What underlies this JavaScript idiom: var self = this?
- Find to do, but could be dangerous because there is a
window.self- see also: Window.self
- Find to do, but could be dangerous because there is a
- Getting Out of Binding Situations in JavaScript
- Awesome tutorial on how
.bindworks
- Awesome tutorial on how