为什么我得到“未定义”错误? [英] Why I got "Undefined" error?
本文介绍了为什么我得到“未定义”错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在js文件中定义了一个对象:
I have defined a object in a js file:
myobj.js
MyObj={
test: {
startTest: function(){
var x = SOME_PROCESS_A;
var y = SOME_PROCESS_B;
return {x: x, y: y};
}
}
}
在我调用的另一个js文件中此对象功能:
In another js file I call this object function:
other.js
var mytest = MyObj.test.startTest
var a = mytest.x;
var b = mytest.y;
my index.html:
my index.html:
<body>
<script src="myobj.js"></script>
<script src="other.js"></script>
</body>
我在 other.js 中遇到了来自firebug的错误, mytest
未定义在 var a = mytest.x;
为什么?
I got the error from firebug in other.js, "mytest
" is undfined in the line "var a = mytest.x;
" Why??
谢谢大家。我在类似的代码中遇到了另一个未定义问题,请查看此处
Thank you,all. I got another "undefined" problem in the similar code, please check here
推荐答案
我认为你打算这样做
var mytest = MyObj.test.startTest(); //calls the function and returns the value to mytest
而不是
var mytest = MyObj.test.startTest;//assigns the function to mytest
这篇关于为什么我得到“未定义”错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文