Skip to content

Instantly share code, notes, and snippets.

@Munter
Created July 17, 2014 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Munter/b6e112edfffdab36ae95 to your computer and use it in GitHub Desktop.
Save Munter/b6e112edfffdab36ae95 to your computer and use it in GitHub Desktop.
An example of using self and bind()
function MyClass(otherInstance) {
var self = this;
self.options = {
loaded: false
};
setTimeout(function () {
self.options.loaded = true;
otherInstance.myClassReady.bind(otherInstance, self);
}, 1000);
}
MyClass.prototype = {
getReady: function (thingsToDo) {
var self = this;
thingsToDo.forEach(function (thing) {
self.do(thing);
});
},
do: function (thing) {
thing.done = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment