Created
November 4, 2011 10:01
-
-
Save robskillington/1339028 to your computer and use it in GitHub Desktop.
callAsync playground
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
// Anonymize | |
(function () { | |
Function.prototype.callAsync = function () { | |
var self = this, args = arguments, result = {returned:false}; | |
setTimeout(function () { result.returnVal = self.apply(self, args); result.returned = true; }, 0); | |
return result; | |
} | |
})(); |
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
var someResult; | |
console.debug(( | |
someResult = function (a, b) { | |
var str = a + ': ' + b; | |
console.log(str); | |
return str; | |
}.callAsync('LogMsg', 'This message was run non-blockingly!') | |
)); | |
// Watch output, someResult will assigned {returned:false} first | |
// Lazy way to test someResult gets updated | |
setTimeout(function () { | |
console.debug(someResult.returned); | |
console.debug(someResult.returnVal); | |
}, 10); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment