PDA

View Full Version : Functions and setting object properties... is this this technique possible...?


krycek
11-10-2002, 12:23 AM
I have been having a few thoughts about objects and their properties. Let's say I have an object, with properties width and height. Now, when I set the properties, I do not JUST want our object's properties to change... I want to change the same properties of ANOTHER object, too. So, I would do this:


function myObject() {
this.width = 100
this.height = 100
}

function myObject2() {
this.width = 100
this.height = 100
}

function setSize(width, height) {
myObject.width = width
myObject2.width = width
myObject.height = height
myObject2.height = height
}


Now, that is all very well, and works fine. But, what I am thinking, is... what if it were possible to somehow code a function whereby this could be done automatically, by simply setting the first object's properties?

i.e.


myObject.width = 200 // somehow sets itself and myObject2.width


Now, the trouble is, it would still have to be possible to GET the value also, which is easy enough by using return. But, is this idea at all possible? I have no idea, and it would be interesting to know how to do it if it is indeed possible. :)

::] krycek [::

krycek
11-10-2002, 08:54 AM
Well I guess everyone is stumped! In which case I can only assume that this is indeed impossible. Pity... it would have been interesting...

::] krycek [::

joh6nn
11-10-2002, 09:37 AM
it should be doable, but it's not. Netscape 4 offered the ability to set up a "listener" ( for lack of a better word ) that would watch an object's properties, and let you fire off some code when the ones you were watching, changed. unfortunately, ECMA seems not to have liked it, and, it's not part of the standard. even if it were standard, it's not like IE has a good record with implementing things, or implementing them correctly, when they do.

ciest la vie

krycek
11-10-2002, 10:33 AM
...ahhhhh!

At least someone knows the answer then :)

Thanks joh6nn - what a pity that that capability was not implemented though :( shame...

::] krycek [::