简体   繁体   中英

How can I access a nested class object in Javascript?

I'm using the node scheduler & it creates an object like so:

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

How can I access the minute.Range.step value?

When I use minute.Range.step , node throws the following error:

TypeError: Cannot read property 'step' of undefined

I've also tried minutes.Range["step"] which is the same as what I tried above.

When you're logging objects in Node, a class name immediately preceding an object tells you want class that object is.

So in your case, when Node logs

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

It actually means that the object you're printing is a plain object, which has a property minute (of type Range ) with its own properties start , end and step .

So to refer to step , you have to use minute.step .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM