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

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

關于 js 函數(shù)默認值的問題

關于 js 函數(shù)默認值的問題

12345678_0001 2019-01-30 09:32:28
下面這兩種寫法為什么會產(chǎn)生兩種不同的結果?求大佬詳細解答.... 個人覺得是跟函數(shù)參數(shù)的塊級作用域有關.....但是理解起來還是怪怪的,而且用 chrome debugger 來查看也覺得怪怪的,為啥最后那個輸入 x,是根據(jù) Block 來輸出的?萬分感謝~function test (x, y = function t () { x = 2 }) {  var x   y()  console.log(x) // undefined} test()function test (x, y = function t () { x = 2 }) {  // var x   y()  console.log(x) // 2}debuggertest()
查看完整描述

1 回答

?
猛跑小豬

TA貢獻1858條經(jīng)驗 獲得超8個贊

9.2.12 FunctionDeclarationInstantiation

If default value parameter initializers exist, a second Environment Record is created for the body declarations.

如果存在函數(shù)默認值,那么會為函數(shù)體部分創(chuàng)建第二個環(huán)境記錄,這個第二個環(huán)境是在函數(shù)默認值之下的。
類似于:

// ES6function foo(x, y = function() { x = 2; }) {  var x = 3;
  y(); // is `x` shared?
  console.log(x); // no, still 3, not 2} 
// Compiled to ES5function foo(x, y) {  // Setup defaults.
  if (typeof y == 'undefined') {
    y = function() { x = 2; }; // now clearly see that it updates `x` from params
  } 
  return function() {    var x = 3; // now clearly see that this `x` is from inner scope
    y();    console.log(x);
  }.apply(this, arguments);
}

代碼來自 es6-notes-default-values-of-parameters


查看完整回答
反對 回復 2019-01-30
  • 1 回答
  • 0 關注
  • 452 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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