Created
January 18, 2019 21:11
-
-
Save mmeyers00/e9f9cdc1f5e378bc8c9f2b2a88858c97 to your computer and use it in GitHub Desktop.
Load external Javascript with a Promise
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 loadjs(file) { | |
| return new Promise(resolve => { | |
| var script = document.createElement("script"); | |
| script.type = "application/javascript"; | |
| script.src = file; | |
| document.body.appendChild(script); | |
| resolve(true); | |
| }); | |
| } | |
| async function main() { | |
| await loadjs('https://code.jquery.com/jquery-3.3.1.min.js'); | |
| console.log($(body).length); | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment