WELCOME Abdennour : Software engineer

May 6, 2014

Stack Overflow is currently offline for maintenance

الجديد في هذه الساعة 

Stack Overflow is currently offline for maintenance





































ِو كانت إجابتي الأخيرة هي هنا: 
http://stackoverflow.com/questions/23504185/javascript-access-return-of-other-function/

HHH






You Can also Pass the context `this` to the second function . However , in this case , you must call f2 as following: 


    function f1(){
      
       return f2.call(this)
    
    }

 --

    function f2(){
       return 123
    }


**UPDATE :** 


Passing context is very useful when you have Oriented Object Programming (`OOP`): 

I.E : 

     function Person(bornYear){
        this.born=bornYear ; 
        this.age=Age.call(this,2014);   
         
      }
    
    function Age(currentYear){
       
      return currentYear-this.age; 
    
    }

 
If you note , `this.age` is not undefined because the context this has been passed from `Person` function to `Age` function

No comments:

Post a Comment