第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

typeof Function.prototype 是 function 為什么不可以當(dāng)作構(gòu)造函數(shù)

typeof Function.prototype 是 function 為什么不可以當(dāng)作構(gòu)造函數(shù)

哆啦的時光機(jī) 2018-10-04 09:19:20
typeof Function.prototype 是 function 為什么不可以當(dāng)作構(gòu)造函數(shù) 與前者有什么
查看完整描述

1 回答

?
呼如林

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個贊

是可以當(dāng)做構(gòu)造函數(shù)來用的

var adder = new Function('a', 'b', 'return a + b');// Call the functionadder(2, 6);// > 8

區(qū)別的話,用構(gòu)造函數(shù)生成的函數(shù)不會有閉包,他們只能訪問自身作用域和全局作用域聲明的變量和函數(shù)。其他詳細(xì)的地方參考MDN

Functions created with the Function constructor do not create closures to their creation contexts; they always are created in the global scope. When running them, they will only be able to access their own local variables and global ones, not the ones from the scope in which the Function constructor was called. This is different from using eval with code for a function expression.

var x = 10;


function createFunction1() {

    var x = 20;

    return new Function("return x;"); // this |x| refers global |x|

}


function createFunction2() {

    var x = 20;

    function f() {

        return x; // this |x| refers local |x| above

    }

    return f;

}


var f1 = createFunction1();

console.log(f1());          // 10

var f2 = createFunction2();

console.log(f2());          // 20


查看完整回答
反對 回復(fù) 2018-11-09
  • 1 回答
  • 0 關(guān)注
  • 477 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號