Skip to content

Instantly share code, notes, and snippets.

@unlocomqx
Created May 25, 2019 21:52
Show Gist options
  • Save unlocomqx/321cf2ae7c9f2cd122e75b092eb953c2 to your computer and use it in GitHub Desktop.
Save unlocomqx/321cf2ae7c9f2cd122e75b092eb953c2 to your computer and use it in GitHub Desktop.
function waitFor( prop ) {
return function( target, key, descriptor ) {
var originalMethod = descriptor.value;
descriptor.value = function (...args) {
const intv = setInterval(() => {
if (typeof window[prop] !== "undefined") {
clearInterval(intv);
originalMethod.apply(this, args);
}
}, 50);
};
return descriptor;
}
}
class Test {
@waitFor("jQuery")
public doStuff() {
console.log((window as any).jQuery);
}
}
const test = new Test();
test.doStuff();
setTimeout(function(){
(window as any).jQuery = function() {};
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment