2016-10-04 95 views
0

我使用的節點計劃&它創建了以下這樣一個對象:如何訪問Javascript中的嵌套類對象?

{ 
    recurs: true, 
    year: null, 
    month: null, 
    date: null, 
    dayOfWeek: null, 
    hour: null, 
    minute: Range { start: 0, end: 59, step: 2 }, 
    second: 0 
} 

我如何可以訪問minute.Range.step價值?

當我使用minute.Range.step,節點引發以下錯誤:

TypeError: Cannot read property 'step' of undefined 

我也試過minutes.Range["step"]這是一樣的就是我上面試過。

+0

'minute.step'或'minute [「step」]'。 – Amadan

+2

'.minute.step'?你爲什麼使用Range? – Oriol

+0

哎呀,我在寫我的問題時意外地輸入了錯誤的值@Amadan - 我編輯了問題以顯示我實際嘗試的內容 – James111

回答

1

當您在Node中記錄對象時,緊接在對象前面的類名告訴您想要類對象是。

所以你的情況,當節點記錄

{ 
    ... 
    minute: Range { start: 0, end: 59, step: 2 }, 
    ... 
} 

它實際上意味着你打印的對象是一個普通的對象,它有自己的屬性start屬性minuteRange型), endstep

所以要引用step,您必須使用minute.step

+0

謝謝澄清!我將刪除我的答案,因爲你的更詳細:) – James111