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)?
Duplicate declarations are simply an equivalent restatement of an interface specification, and that has no effect on code which depends on that interface.
JavaScript allows for the nesting of functions and grants the inner function full access to all the variables and functions defined inside the outer function (and all other variables and functions that the outer function has access to).
In JavaScript, a function allows you to define a block of code, give it a name and then execute it as many times as you want. A JavaScript function can be defined using function keyword.
The function declaration (function statement) defines a function with the specified parameters. You can also define functions using the Function constructor and a function expression.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With