0
method.getTotalDays = function(){
    return (this.longi-this.age)*365;
}

method.eatPercent = function(){
    return this.eat/24;
}

In my next method within this constructor, I want to calculate the days that "eating process" costs in my life. For example, I want to have a method like this:

method.getEatingDays = function(){
var days = 0;
days = eatPercent*totalDays; //How do I get eatPercent and totalDays by using the established  
                             //methods?
}
1
  • this.eat is in terms of hours. Commented Aug 21, 2013 at 3:31

2 Answers 2

2

If the method is defined as an object, you can do

days = method.eatPercent() * method.totalDays();

If method is a function, then you need

days = this.eatPercent() * this.totalDays();

this here refers to the owner which calls getEatingDays()

Sign up to request clarification or add additional context in comments.

Comments

1

You need to call those getter function in the current instance, this can be done via this.fnName()

method.getEatingDays = function(){
var days = 0;
days = this.eatPercent()*this.getTotalDays();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.