Last active
November 3, 2019 10:07
-
-
Save agusputra/b31ff53ec9eddb6a37d9603816091b91 to your computer and use it in GitHub Desktop.
do-if-jquery.js
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
const detectJQuery = () => typeof jQuery !== 'undefined' | |
doIf(detectJQuery, main, 1000) | |
function main() { | |
jQuery(($) => { | |
// jQuery detected | |
}) | |
} | |
function doIf(predicate, callback, timeOut) { | |
setTimeout(() => { | |
if (predicate()) { | |
callback() | |
} | |
else { | |
doIf(predicate, callback); | |
} | |
}, timeOut) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment