document.createElement(“script”) synchronously

前端 未结 11 2328
执念已碎
执念已碎 2020-11-22 12:56

Is it possible to call in a .js file synchronously and then use it immediately afterward?



        
11条回答
  •  梦谈多话
    2020-11-22 13:45

    Ironically, I have what you want, but want something closer to what you had.

    I am loading things in dynamically and asynchronously, but with an load callback like so (using dojo and xmlhtpprequest)

      dojo.xhrGet({
        url: 'getCode.php',
        handleAs: "javascript",
        content : {
        module : 'my.js'
      },
      load: function() {
        myFunc1('blarg');
      },
      error: function(errorMessage) {
        console.error(errorMessage);
      }
    });
    

    For a more detailed explanation, see here

    The problem is that somewhere along the line the code gets evaled, and if there's anything wrong with your code, the console.error(errorMessage); statement will indicate the line where eval() is, not the actual error. This is SUCH a big problem that I am actually trying to convert back to

提交回复
热议问题