B
blaine
Hey,
I'm trying to do a loading routine that would act like php's require
once. The reason for this is I have a few classes that may or may not
be used on a page. If more then one is used then some of them require
similar base objects.
Anyhow, below was my first idea of a require once loader.. Check the
this variable (window object) for the class name you are looking for
and if it does not exists then load the class. If it does then skip
the class.
In theory it seems good.. In practice it never finds any of the loaded
classes. Any ideas?
// file1 names also indicate function name
//ie file1.js contains var file1 = function();
var files = new Array('file1','file2','file3');
var files2 = new Array('file1','file4');
function loadFiles( files ){
for (var i=0; files.length > i; i++){
//check to see if the class is already loaded.
if ( key in this == false ){
document.write("<SCR" + "IPT LANGUAGE='JavaScript' SRC='"
+ path + files + ".js' TYPE='text/javascript'><\/SCR" + "IPT>");
}
}
}
loadFiles( files );
loadFiles( files2 );
I'm trying to do a loading routine that would act like php's require
once. The reason for this is I have a few classes that may or may not
be used on a page. If more then one is used then some of them require
similar base objects.
Anyhow, below was my first idea of a require once loader.. Check the
this variable (window object) for the class name you are looking for
and if it does not exists then load the class. If it does then skip
the class.
In theory it seems good.. In practice it never finds any of the loaded
classes. Any ideas?
// file1 names also indicate function name
//ie file1.js contains var file1 = function();
var files = new Array('file1','file2','file3');
var files2 = new Array('file1','file4');
function loadFiles( files ){
for (var i=0; files.length > i; i++){
//check to see if the class is already loaded.
if ( key in this == false ){
document.write("<SCR" + "IPT LANGUAGE='JavaScript' SRC='"
+ path + files + ".js' TYPE='text/javascript'><\/SCR" + "IPT>");
}
}
}
loadFiles( files );
loadFiles( files2 );