Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: More Efficient

  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question More Efficient

    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)
    Code:
    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)
    Last edited by vkidv; 08-18-2005 at 12:49 AM.
    Regards
    VKiDV

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow

    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.

    this.Parent.Method()
    Regards
    VKiDV


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •