美文网首页
return function 和return function

return function 和return function

作者: YanniLi | 来源:发表于2017-10-26 11:59 被阅读0次

return function 示例 —— 返回的是一个函数

function a() {
    console.log('aaa')
    function b() {
        console.log('bbb')
    }
    return b
};

a(); // aaa

var s = a();
console.log(s) // 整个a()函数
s(); // aaa bbb


var s = a();
console.log('111')
s(); // aaa 111 bbb

return function() 示例 —— 返回的是函数执行结果

function a() {
    console.log('aaa')
    function b() {
        console.log('bbb')
    }
    return b()
};

a(); // aaa bbb

var s = a();
console.log(s) // undefined
s(); // aaa bbb s is not a function 


var s = a();
console.log('111')
s(); // aaa bbb 111 s is not a function

--------------------------

function a() {
    console.log('aaa')
    function b() {
        console.log('bbb')
        return 1000
    }
    return b()
};

var s = a();
console.log(s) // 1000


相关文章

网友评论

      本文标题:return function 和return function

      本文链接:https://www.haomeiwen.com/subject/smohpxtx.html