我正在看一些示例代码:
function iLoveCheese(){
return {
'c': thenumber, 'd': anothernumber
}
}
说我想在程序中使用'thenumber',我可以这样做: -
function lotsOfCheese(){
var t = iLoveCheese();
return t.thenumber;
}
是否正确理解?
答案 0 :(得分:0)
您的lotsOfCheese
功能无法正常运行。这是因为ILoveCheese
函数返回对象。您需要通过键来引用此对象,而不是值。
function lotsOfCheese(){
var t = iLoveCheese();
return t.c; // "c" is the key of the object t
}
这将返回一个值thenumber