Skip to content

Instantly share code, notes, and snippets.

@agusputra
Last active November 3, 2019 10:07
Show Gist options
  • Save agusputra/b31ff53ec9eddb6a37d9603816091b91 to your computer and use it in GitHub Desktop.
Save agusputra/b31ff53ec9eddb6a37d9603816091b91 to your computer and use it in GitHub Desktop.
do-if-jquery.js
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