I tried to call from child object a parent attribute
var parentObj = {
attr1:1,
attr2:2,
childObj:{
method1:function(){
return this.attr1 * this.attr2;
}
}
}
but it doesn't work.
I tried to call from child object a parent attribute
var parentObj = {
attr1:1,
attr2:2,
childObj:{
method1:function(){
return this.attr1 * this.attr2;
}
}
}
but it doesn't work.
This is an another approach without referencing the parent object's name.
Can be accessed as:
This can be done with the power of closures!
Try referencing
parentObj
directly:There is a problem with referencing parent object my name because it breaks the app in case you rename it. Here is nicer approach, which I use extensively, where you pass the parent as an argument to the child
init
method: