我想設置一個屬性,我還沒有創建一個對象。它似乎並不想讓我在飛行中添加屬性,而且它必須以這種方式完成。爲什麼我收到錯誤:不能在未定義的對象上設置屬性
TypeError: 'undefined' is not an object (evaluating 'someItem.anotherProperty = "someOtherValue"')
我不明白爲什麼我不能上動態變量someItem
設置屬性。當我想要一個對象(在這種情況下爲someItem
)時,我可以添加任何我想要的Javascript的全部內容嗎?
這裏是我的代碼:
testObject = function() {
var someItem;
someItem.anotherProperty = "someOtherValue";
function doStuff() {
someItem.someProperty = "someValue";
}
};
function start() {
item = new testObject();
item.doStuff();
}