javascript参数传递不工作显示未捕获TypeError:无法读取属性' substr'未定义的

时间:2015-11-29 19:31:07

标签: javascript asp.net three.js

我在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;未定义的

1 个答案:

答案 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>