Search code examples
functionobjectjscript

Getting retun value of function object in jScript


I have a j Script function like below

function a(){
\\ do something
if (X=y){
  \\do other things
   {
else {
  return false
   }
//Do final things
return true
}

then I call that

function b(){
var P = new a();
log p.valueOf() //this always equal to 'object object'

}

Can some body please help me on how to get return value of function a() within b()


Solution

  • If all you want to do in function b() is evaluate function a() and log its value, you don't need var p. valueOf() does not evaluate a function, and declaring p = new a(); does not make p a function. ref

    Just evaluate a(), and store its result in p. fiddle:

    function b(){
        var p = a();
        console.log(p); //should output `true` or `false`
    }