Created
May 25, 2019 21:52
-
-
Save unlocomqx/321cf2ae7c9f2cd122e75b092eb953c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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