Tom
Tom

Reputation: 5

Load a script within a function

I am trying to load a script within a function that depends on a variable of that function. Basically, the code is like this

head.js("somescript.js", function() {

   var dependentVar = //stuff;

    //insert script here which depends on dependentVar
});

Is this possible or anyone know how I can do this ? I need to do this because dependentVar contains C# code ?

Upvotes: 0

Views: 97

Answers (2)

John Kalberer
John Kalberer

Reputation: 5800

You mean like this?

$.getScript("somescript.js", function() {

   var dependentVar = //stuff;

    //insert script here which depends on dependentVar
    if(dependentVar) {
        $.getScript("somescript2.js", function() {

        });    
    }
});

Upvotes: 0

George Cummins
George Cummins

Reputation: 28936

This sounds like a design flaw. Instead of loading the code on the fly, can you encapsulate it in a function and pass dependentVar as a parameter?

Upvotes: 1

Related Questions