inheritance - How to pass javascript object value to its "child" object -


I am trying to pass a variable for a child object of my original object, but its return is undefined. (Obviously I'm not sure how a JS object works)

  var = {pid: '565', child: {cid: this.pid + '_child_789', say hello: function () {warning ('my id is' + this.cid ); }}}   

Calling parent.child.sayHello () log this.cid as undefined.

I am wrong (wrong) thinking that the child will be the heir to the property of the property and it can be specified by this.pid , but can not do it.

Is there any way to do this with a hard-coding quality?

I know that I can do this after creating the parent.child.cid = parent.pid + '_child_789' object, but it is not scalable or practical for me.

You can not use that kind of property in your object; I will go into more detail, However, this question has already been answered several times in advance. Please review the following questions:



Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -