View Full Version : More Efficient

08-18-2005, 12:46 AM
Can anybody show me how I can make this more efficient?
(The parts underlined is what I mean, the whole code is just an example)

function Animal( Name, Age ) {
this.Name = Name ;
this.Age = Age ;
this.Statistics = new Statistics(this) ;
this.Statistics.Calculate() ;

function Statistics( Parent ) {
this.Parent = Parent ;
this.Calculate = Calculate ;

function Calculate() {

this.Weight = this.Parent.Age * 2 ;

var myFish = new Animal("Geoffrey",.5) ;
alert(myFish.Statistics.Weight) ;

This was my finishing solution to my problem last time: http://www.codingforums.com/showthread.php?t=65019
but I believe it could be more efficient.

Can a Parent property be added to all objects? This would mean I wouldn't have to pass 'this' everytime I make an object (in bold)

08-18-2005, 05:17 PM
Sorry to repost, does anyone know the answer?

Another way to phrase my question is HOW to give every object a 'Parent' property - so every object can access its parents methods+properties.