What I want is to load multiple files. These files all use the same function to be loaded, only thing different is the file name. This function should return an object. Something like this:
var files = [ loadFile("file1.txt"), loadFile("file2.txt"), loadFile("file3.txt") ];
// Example function
function loadFile( file_name ) {
return "loaded file " + file_name;
}
But when I run this it loads it directly.
var files = [ loadFile, loadFile, loadFile ];
// now please
for (var i = 0; i < files.length; i++) {
files[i]();
}
But this way I can't give it arguments. Now I can create a filler function like this, but I there is probably a better way to do this...
function loadFile1() {
return loadFile( "file1.txt" );
}
If it is possible, how can I load Javascript functions as Arguments with Arguments?
*done some testing. I am going with bind() for the answers, as that is what I was looking for. But I want to mention Stuart's answer that I definitely will keep in mind for the future use. MoeSattler & vlaz thank you guys for showing other good ways of doing this!
bind()or make another function or lambda..bindto be a better way, then yes. Otherwise, no.