6

If i have code:

function A() {

  function B() {

  }

  B();

}

A();
A();

is B function parsed and created each time i call A(so it can decrease performance of A)?

000
  • 26,951
  • 10
  • 71
  • 101
Krab
  • 6,526
  • 6
  • 41
  • 78

2 Answers2

2

If you want use a function only internally, how about closure. Here an example

    var A = (function () {
    var publicFun = function () { console.log("I'm public"); }
    var privateFun2 = function () { console.log("I'm private"); }

    console.log("call from the inside");
    publicFun();
    privateFun2();

    return {
        publicFun: publicFun
    }
})();   

console.log("call from the outside");
A.publicFun();
A.privateFun(); //error, because this function unavailable
IgorCh
  • 2,641
  • 5
  • 22
  • 29
2
function A(){

    function B(){

    }
    var F=function(){
        B();
     }
     return F;
}
var X=A();
//Now when u want to use this  just use this X function it will work without parsing B() 
Robins Gupta
  • 3,143
  • 3
  • 34
  • 57