javascript, new object recursively

On jsbin I tested to see if this will work:

var person = new Object();
person.anon = new Object();
person.anon.name = "Someone";

well yes. Next I tried to put it to work where I needed in my code:

let task = new Object();
task.assigned = new Object();
tasks.assigned.word = w_prepared[tasks[z].assigned].word;

and I get the error:

TypeError: Cannot set property 'word' of undefined

I tried various way of expressing, all failed. Perhaps I don't understand something fundamental here.

Could you please tell me what's wrong?

Upvotes: 1

Views: 41

Answers (2)

RegarBoy
RegarBoy

Reputation: 3521

You didn't create object with name tasks yet. So that you cannot set property to an undefined object.

Upvotes: 2

Harald Gliebe
Harald Gliebe

Reputation: 7564

Use

task.assigned.word = ...

instead of

tasks.assigned.word = ...

Upvotes: 3

Related Questions