为什么我会得到“未定义"的字样?信息? [英] Why did I get "Undefined" message?
本文介绍了为什么我会得到“未定义"的字样?信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在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;
我的index.html:
my index.html:
<body>
<script src="myobj.js"></script>
<script src="other.js"></script>
</body>
我在 other.js 中从Firebug中得到了错误,"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屋!
查看全文