var loadJavaScriptFiles = {
jQuery : "ljs",
core : "js",
common : "tjs",
}
function dynamicLoad(filesArray){
var i = 0
var fname = new Array
var fileref = new Array
var fileSRC = {
ljs : "engine/javascript/library/",
js : "engine/javascript/",
tjs : "templates/{LANG}/{TEMP}/javascript/",
css : "engine/pages/css/",
tcss : "templates/{LANG}/{TEMP}/css"
}
for (var key in filesArray) {
var filetype = filesArray[key]
var fileName = key
if (filetype=="js"|| filetype=="ljs" || filetype=="tjs") {
fileref[i]=document.createElement('script')
fileref[i].setAttribute("type","text/javascript")
fileref[i].setAttribute("src", fileSRC[filetype] + fileName + ".js")
fname[i] = fileName + ".js"
}
else if (filetype=="css" || filetype=="tcss"){
fileref[i]=document.createElement("link")
fileref[i].setAttribute("rel", "stylesheet")
fileref[i].setAttribute("type", "text/css")
fileref[i].setAttribute("href", fileSRC[filetype] + fileName + ".css")
fname[i] = fileName + ".css"
}
if (typeof fileref[i]!="undefined") {
document.getElementsByTagName("head")[0].appendChild(fileref[i])
}
i = i + 1;
}
for (i = 0; i<fileref.length; i++) {
fileref[i].onload = function() {
console.log(fname[i] + " loaded successful")
}
fileref[i].onerror = function() {
console.log("Some error occurred with loading " + fname[i])
}
}
}
</script>
<script>
dynamicLoad(loadJavaScriptFiles);
</script>
Вот, выделил основное в скрипте. Вопрос, почему в логах консоли выводится: undefined loaded successful? Заранее спасибо!