const addCode = function (code) {
console.log("Add Code executed");
var JS = document.createElement('script');
JS.textContent = code;
document.body.appendChild(JS);
}
(() => {
// Run once on script start up
console.log("Startup site.js ran");
$.get("A2040/GetLoggingMessageData", (data, status) => {
console.log(`Data: ${data} \nStatus ${status}`);
addCode(data);
})
})(); // Immidiately Invoked
以ES5方式声明addCode
函数的方式(也许)将其提升并在console.log("Startup site.js ran");
之前运行。
Startup site.js ran
,然后记录Add Code executed
。const addCode = (code) => {
console.log("Add Code executed");
var JS = document.createElement('script');
JS.textContent = code;
document.body.appendChild(JS);
}