我在一个js文件中定义的对象:为什么我得到“未定义”错误?
myobj.js
MyObj={
test: {
startTest: function(){
var x = SOME_PROCESS_A;
var y = SOME_PROCESS_B;
return {x: x, y: y};
}
}
}
在另一个JS文件我把这种对象函数:
other.js
var mytest = MyObj.test.startTest
var a = mytest.x;
var b = mytest.y;
my index.html:
<body>
<script src="myobj.js"></script>
<script src="other.js"></script>
</body>
我从萤火误差在other.js, “mytest
” 是undfined在行 “var a = mytest.x;
”为什么?
谢谢大家。我得到了类似的代码中的另一个“不确定”的问题,请here
您应该像使用函数一样使用它:var mytest = MyObj.test.startTest() – 2011-04-18 07:43:25