James111 James111 - 1 year ago 67
Javascript Question

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

When I use
, node throws the following error:

TypeError: Cannot read property 'step' of undefined

I've also tried
which is the same as what I tried above.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download