views:

52

answers:

1

Hi,

I'm a little confused about the best practice to achieve the following: I have an object which requires the load of 2 JS libraries(jQuery and swfobject), who may be already loaded or not, so i have to check both before calling the final method (output). Another tricky thing is that i have to pass some arguments to the initial method (gen) and those args must pass to output. Should i use .apply?

    var myfancymethod = {
    zclk: "string1",
    zclk2: "string2",

    loadsrc: function(what){
        jQuery.getScript(what, function() {
            alert (what+ "loaded");

        });
    },


    checklibs: function(){
        if (typeof libA == "undefined") {
            this.loadsrc("libA.js");
        }
        if (typeof libB == "undefined") {
            this.loadsrc("libB.js");
        }

    },

    output: function (a, b, c){
        //final output here
    },


    gen: function(a, b, c, d){
        //have to check if libray A and B are loaded
        this.checklibs();

        //call to output()
        ?




    }




myfancymethod.gen(a, b, c, d );
A: 

If you place your libraries in the right order in the HEAD part of your page, they will arrive in that order. So no need for the "checklibs" logic.

And then to be sure all is loaded, the DOM elements included. You place the call to your "output" function in a SCRIPT tag at the end of the BODY tag.

Mic