有趣的JS

以下代码段的作用是?

 function addN(n){
        var adder = function(x){
            return n+x;
        }
        return adder;
    }

  

这段代码展现出了js 不同于其他语言的一个特性,first class. 试着打印结果:

var add2=addN(2);
console.log(add2);
var result = add2(100);
console.log(result)

Output:

function (x){
            return n+x;
        }
102

 

特性:可以返回function ! 太屌了。

 

posted @ 2014-12-28 22:58  拙急鸟  阅读(140)  评论(0编辑  收藏  举报