return function 和return function() 的区别

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() 的区别)