我在js文件中有一个javascript代码,它有以下功能
var obj, mtl;
init();
animate();
var MYLIBRARY = MYLIBRARY || (function () {
var _args = {}; // private
return {
init: function (Args) {
_args = Args;
// some other initialising
},
getValue: function () {
obj = _args[0];
mtl = _args[1];
}
};
} ());
现在我想将一些值传递给MYLIBRARY
,这样我可以使用它;
但是当我将值传递给
<script src="App_Themes/Assets/js/loaders/JScript.js" type="text/javascript"></script>
<script type="text/javascript">
MYLIBRARY.init(["obj/Dress/anarkali.obj", "obj/Dress/anarkali.mtl"]);
MYLIBRARY.getValue();
</script>
它给了我这个错误
未捕获的TypeError:无法读取属性&#39; substr&#39;未定义的
答案 0 :(得分:0)
实际上这个问题是错误的
MYLIBRARY
的定义位于Jscript.js
中,而args位于
所以,我将MYLIBRARY
放在Jscript.js
<script>
var MYLIBRARY = MYLIBRARY || (function () {
var _args = {}; // private
return {
init: function (Args) {
_args = Args;
// some other initialising
},
getValue: function () {
obj = _args[0];
mtl = _args[1];
}
};
} ());
</script>
之后这段代码
<script type="text/javascript">
MYLIBRARY.init(["obj/Dress/anarkali.obj", "obj/Dress/anarkali.mtl"]);
MYLIBRARY.getValue();
</script>
<script src="App_Themes/Assets/js/loaders/JScript.js" type="text/javascript"></script>