Skip to content Skip to sidebar Skip to footer

Javascript Variable Declared As Code And Reuse

I have a jquery enabled javascript app that has a variable that is declared as a substantial hunk of code. var Listings = Spine.Controller.sub({ TPL: Handlebars.compile( $( '#e

Solution 1:

Change your code to this:

function giveMeAName() {
    return Spine.Controller.sub({
        // massive code here
    });
}

Then you can include that file via jQuery as you would normally. After including, do this:

var Listings = giveMeAName();
var SomethingElse = giveMeAName();

You can also pass parameters, if the two uses of the code differ slightly.

Post a Comment for "Javascript Variable Declared As Code And Reuse"