闭包是js中一个难懂又必须征服的概念,他的形成与变量作用域以及变量的生存周期密切相关。
变量作用域和生存周期
作用域,按字面理解,就是指变量的有效范围,超出这个范围就无法访问。
在函数中,里面函数可以访问外面的变量,但是外面无法访问内部变量。举个简单例子:
var a = 1;
var fun1 = function() {
var b = 2;
var fun2 = function() {
var c = 3;
alert(b); //2
alert(c); //3
}
fun2();
alert(c); //c is not de继续阅读 »
For the performance tuning, the simplest way is to record how many time is elapsed in a function. The only difficulty we’re facing is that: there maybe many exit for a function. Thanks to C++’s constructor/deconstructor feature, it’s easy for developer to record the elsaped time.继续阅读 »
xmake provides some api, which can detect whether exist some library functions.
```lua
target("test")
-- checks some libc functions from the header files: wchar.h and stdlib.h
add_cfuncs("libc", nil, {"wchar.h", "stdlib.h"}, "wcscat",
继续阅读 »