0
我試圖從object
中訪問property
。當我通過手動輸入路徑訪問property
時,我可以檢索它,但不能在動態輸入時動態地。使用JavaScript從內部方法訪問屬性
我在下面錯過了什麼?
var myApp = {
cache : {},
init: function() {
myApp.cache.akey = 'A value'; // Set the cached value
myApp.get('cache', 'akey');
},
get: function(from, key) {
console.log(myApp.from.key); // undefined
console.log(myApp.cache.akey); // A value
}
};