Skip to content

Instantly share code, notes, and snippets.

@muromec
Last active September 2, 2015 14:23
Show Gist options
  • Save muromec/ea5cf4ab422c223e737b to your computer and use it in GitHub Desktop.
Save muromec/ea5cf4ab422c223e737b to your computer and use it in GitHub Desktop.
function MyObject(val) {
this.val = val;
this.myCallback = this.myCallback.bind(this); // or lodash.bindall(this, 'myCallback');
}
MyObject.prototype.myCallback = function(err, data){
console.log(err,data);
console.log(this.val);
};
function methodThatTakesSomeTime(callback){
// some time later...
for(var i = 1; i<100000; i++){
//simulate long
}
var err='knall';
var data = Math.random();
callback(err, data);
}
var testObj = 0;
for(var i = 1; i<10; i++){
testObj = new MyObject(i);
methodThatTakesSomeTime(testObj.myCallback) // don't be fuckin Ru***ki, use Promise and .then()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment