最近我读过这个性能指南让我们更快地使网络变得困惑并且被"避免关闭陷阱"建议所迷惑(好像这些建议是针对变量范围是动态的CommonLisp用户提供的):
Run Code Online (Sandbox Code Playgroud)var a = 'a'; function createFunctionWithClosure() { var b = 'b'; return function () { var c = 'c'; a; b; c; }; } var f = createFunctionWithClosure(); f();
f调用when时,引用a比引用慢b,这比引用慢c.
很明显,引用局部变量c比b快,但是如果iterpreter写得正确(没有动态范围 - 类似于链式散列表查找......),速度差异应该只是边际.或不?
javascript performance closures interpreter functional-programming