Skip to content

Instantly share code, notes, and snippets.

@khamiltonuk
Created March 5, 2014 17:06
Show Gist options
  • Select an option

  • Save khamiltonuk/9371531 to your computer and use it in GitHub Desktop.

Select an option

Save khamiltonuk/9371531 to your computer and use it in GitHub Desktop.
Understanding This
// Bad
var myObj = {
specialFunction: function () {
},
anotherSpecialFunction: function () {
},
getAsyncData: function (cb) {
cb();
},
render: function () {
var that = this;
this.getAsyncData(function () {
that.specialFunction();
that.anotherSpecialFunction();
});
}
};
myObj.render();
// Good
var myObj = {
specialFunction: function () {
// Statements
console.log('hello1');
},
anotherFunction: function () {
// Statements
console.log('hello2');
},
getAsyncData: function (cb) {
// Statements
console.log('hello3');
cb();
},
render: function () {
this.getAsyncData(function(){
this.specialFunction();
this.anotherFunction();
}.bind(this));
}
};
myObj.render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment