I have a function as below.
My Problem is that I need to print function b()
inside a function. Here function a()
is parent function. and I have done it by taking c= new a()
and console.log(b())
. I got the right value as I expected. But inside the parent function I have another function named test()
and with same name there is another function outside the parent function. After printing function b()
I call the function test()
. But it return the value from the parent function. I need to get an alert as needed answer
which is in outer function. Is there any way to get my expected result without changing the function name.? Both functions test()
are needed.
Expected result:
function b()
= 2 andfunction test()
= needed answerCurrent result :
function b()
= 2 andfunction test()
= 4
Any help will be appreciated. Thank You.
function a() {
var val = 1;
var otherval = 2;
b = function() {
return val + 1;
}
test = function() {
qwerty = otherval + b();
alert(qwerty);
}
return 'OK';
}
function test(){
alert('needed answer');
}
c = new a();
console.log(b()); //return 2
test(); //alert 4 but I needed alert needed answer