- function makefunc(x)
- {
- return function(){return x;}
- }
- var a = [makefunc(0),makefunc(1),makefunc(2)];
- alert(a[0]());
- //result 0
- alert(typeof(a[0]));
- //result function
- alert(a[0]);
- //result function(){return x;}
- var y = "global";
- function constructFunction() {
- var y = "local";
- return new Function("return y"); // Does not capture the local scope!
- }
- // This line displays "global" because the function returned by the
- // Function() constructor does not use the local scope. Had a function
- // literal been used instead, this line would have displayed "local".
- alert(constructFunction()()); // Displays "global"
javascript有趣的现象----函数
最新推荐文章于 2020-11-12 12:06:58 发布