Skip to content

Instantly share code, notes, and snippets.

@oshanz
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oshanz/3bf275b61512b1ec0fa7 to your computer and use it in GitHub Desktop.
Save oshanz/3bf275b61512b1ec0fa7 to your computer and use it in GitHub Desktop.
getScript More
function loadOrdered(files, callback) {
$.getScript(files.shift(), function() {
files.length
? loadOrdered(files, callback)
: callback();
});
}
edit, a nicer version:
function loadOrdered(files, callback) {
$.getScript(files.shift(), files.length
? function(){loadOrdered(files, callback);}
: callback
);
}
or even nicer, if you don't care about old browsers or implement Function.prototype.bind yourself (with support for binding arguments too, and not just the this context):
function loadOrdered(files, callback) {
$.getScript(files.shift(), files.length
? loadOrdered.bind(null, files, callback)
: callback
);
}
/////////////////////////////////////////////////////////////////////
var links = [
"session/js/invoice_product_table",
"session/js/invoice_return_table",
"session/js/invoice_replace_table",
"session/js/invoice_empty_table",
"session/js/invoice_sample_table",
"session/js/invoice_validations",
"session/js/invoice"
];
links.forEach(function(val) {
var script = document.createElement('script');
script.src = URL + "view/" + val + ".js";
document.getElementsByTagName('head')[0].appendChild(script);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment