今天看代码时发现有一个function里return了一个object对象,而其他地方直接应用了这个对象的内容。然后自己就尝试做一些个东西试试是否可行:
var test = function (){
return {init: 'ab', todo: 'sth'};
}
alert(typeof test.init);// alert undefined
var a = test.init;
alert(a);// alert undefined
发现不行;
后来细看了一下代码发现,原来后面还有一个“();”,然后再test的后面加了这个就好了。
var test = function (){
return {init: 'ab', todo: 'sth'};
}();// add different with up
alert(typeof test.init);// alert string
var a = test.init;
alert(a);// alert ab
OK了。。。
总结一点就是没有细看后面的()