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 [::
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 [::