|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm by no means a javascript expert, and to be quite honest the functional prototype based object orientation of the language is something I'm still trying to wrap my head around as it bears little resemblance at all to the C++/Java/PHP style I'm used to.
So, my question is about accessing "parent" object members via "children". In this case, I'm not even sure if the words parent and child are accurate because it's more akin to an object within an object as opposed to the traditional inheritance model. So, to make it as simple as possible to demonstrate: Code:
objectA = {
objectAMethod1: function() {
ObjectB = function() {
}
}
};
Given this type of scenario, how would I access members of objectA from within objectB?
__________________
-Jason |
|
#2
|
|||
|
|||
|
Using statements like this: objectA.<name_of_an_objectA's_method>. I see that you're asking about something like ObjectB.parent.parent.... but it's not supported yet. BTW we dont say objects in JS have parents, instead we say objects have their owners. It is the sole concept of JS. That's why event handlers on DOM nodes can only access that nodes using 'this' but not the objects they were declared within.
But...generally you may do this: take outermost object and walk thru its contents attaching a property to every descendant that points to its immediate parent. I cant say is it bad or good but it solves the problem however. Last edited by NetSurfer : September 19th, 2007 at 01:56 PM. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Advanced OO Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|