path list as a array #139

Closed
sjoonk opened this Issue May 13, 2011 · 5 comments

Projects

None yet

5 participants

@sjoonk
sjoonk commented May 13, 2011

I'd like to change the path list of head.js method.
Is there any way to pass the path list as an array??

@CreativeTransmissions

I'm just testing this on a large project and found the following method works for loading in parallel and executing in sequence:

//Create or generate an array of scripts
var scripts = ['Includes/error.js', /adapter/ext/ext-base.js', '/Components/cmpBase.js'];

//Use Javascript's apply method to call the head.js function
head.js.apply(window, scripts);

Hope this helps someone.

@EnzoMartin

Wishing we could pass in an array, that'd be really useful.

The .apply work-around doesn't make for easy callback handling

@itechnology
Contributor

will give this some more thought.

The apply example would look like this more likely with a callback

head.js.apply(window, scripts.push(callback));
@EnzoMartin

I wrote a quick workaround for my own purposes for now, nothing fancy:

var args      = arguments,
     callback = args[args.length - 1],
     items    = {};

if (!isFunction(callback)) {
    callback = null;
}

 if (isArray(args[0])) {
    var arrArgs = args[0];
    args = [];
    each(arrARgs, function (arg) {
        args.push(arg);
    });
    args.push(callback);
}
@robert-hoffmann
Member

Shipping in 1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment