Last active
August 29, 2015 14:03
-
-
Save oshanz/3bf275b61512b1ec0fa7 to your computer and use it in GitHub Desktop.
getScript More
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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