Created
June 5, 2018 21:57
-
-
Save neoeno/69bb666e763a730eff0f0d098eb50772 to your computer and use it in GitHub Desktop.
fakeBrowser.js
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 fakeBrowser(initial) { | |
const functionsToRun = [initial]; | |
const fakeWindow = { | |
addCallback: function(fn) { | |
functionsToRun.push(fn) | |
} | |
} | |
while(functionsToRun.length > 0) { | |
const nextFn = functionsToRun.shift(); | |
nextFn(fakeWindow) | |
} | |
} | |
fakeBrowser(function(window) { | |
console.log("Hi!") | |
window.addCallback(function() { | |
console.log("Hey!") | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment