This is what i am facing with
function AAA(){
this.f1 = function (){
/*expecting that f2 will be call as both of then are of same object.*/
console.log(f2(5));//
}
this.f2 = function(x){
return x;
}
}
x = new AAA();
x.f1(); //ReferenceError: f2 is not defined
Neither does it work,
function AAA(){
this.f1 = function (){
/*expecting that f2 will be call as both of then are of same object.*/
console.log(f3(5));//
}
/*naming the function f3 hope to get function reference, as function
on the right side has name now and in the closure of f1, right?*/
this.f2 = function f3(x){
return x;
}
function f4() {};
}
x = new AAA();
x.f1(); //ReferenceError: f3 is not defined
What is happening here? who are in closure of 'f1' except 'f4'? can't we call the same object function without 'this'?