Skip to content

Instantly share code, notes, and snippets.

@neoeno
Created June 5, 2018 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neoeno/69bb666e763a730eff0f0d098eb50772 to your computer and use it in GitHub Desktop.
Save neoeno/69bb666e763a730eff0f0d098eb50772 to your computer and use it in GitHub Desktop.
fakeBrowser.js
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