Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  86] [ 5]  / answers: 1 / hits: 20752  / 12 Years ago, thu, june 28, 2012, 12:00:00

I have a code like that:



User = function(){}

User.a = function(){
return try;
}

User.b = function(){

}



From User.b() I can call User.a() using:



User.b = function(){
return User.a();
}


but not using this since it's not an instance of user (User.a() and User.b() are something like static methods).



What i want to do is to be able to call User.a() from User.b() without knowing which is the main function, in this case User.



Something like this to be used in static methods.


More From » oop

 Answers
6

In reality there is no methods or static methods in js, there's just functions that are assigned to object properties (functions being objects as well) and they all work the same way. Since you are calling it like User.b(), this will be User for the call.



User.b = function() {
return this.a();
}

[#84588] Wednesday, June 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaden

Total Points: 709
Total Questions: 91
Total Answers: 91

Location: Maldives
Member since Sat, Jan 29, 2022
2 Years ago
;