如果我有代码:
function A() {
function B() {
}
B();
}
A();
A();是否每次我调用A时都会解析并创建B函数(因此它会降低A的性能)?
发布于 2013-07-16 16:14:39
如果你只想在内部使用一个函数,那么闭包怎么样?下面是一个示例
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发布于 2013-07-16 16:17:26
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() https://stackoverflow.com/questions/17670954
复制相似问题