Created
June 11, 2020 03:30
-
-
Save djD-REK/07d86e495bc772133907b63317c3ea56 to your computer and use it in GitHub Desktop.
This file contains 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
// <script src="https://code.jquery.com/jquery-3.5.0.js"></script> | |
const loadScript = async (url) => { | |
const response = await fetch(url) | |
const script = await response.text() | |
Function(script) | |
} | |
const scriptUrl = "https://code.jquery.com/jquery-3.5.0.js" | |
loadScript(scriptUrl) | |
// Use jQuery: | |
$("div").css("border", "3px dotted orange") |
It looks to me that the code « Function(script) » will not execute.
You can make it a Self-Invoking Functions « (Function(script))() »
https://scriptverse.academy/tutorials/js-self-invoking-functions.html
Great point @Omsteker ! It's missing that extra pair of parentheses, one key difference from eval.
I should probably split the whole eval / Function discussion into another article, because it's off topic compared to using appendChild
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Function(script) not equal eval
Eval run code
Function only creates a function