Last active
September 2, 2015 14:23
-
-
Save muromec/ea5cf4ab422c223e737b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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