JavaScript: variable & scope

 

let b = {
  n1: 11,
  n2: 22,
  n3: 44,
  n4: 55,
  ns: {
    n1, n2
  }
}

 

 

n1 n2 不是变量, 是b的key

 

let t={22,33}

let b = {
  n1: 11,
  n2: 22,
  n3: 44,
  n4: 55,
  ns: {
    this.n1, this.n2
  }
}

错误的对象定义方式

 

let b = {
  n1: 11,
  n2: 22,
  n3: 44,
  n4: 55,
  ns: () => console.log(this),
  nss: function () {
    console.log(this)
  }
}

b.ns()
b.nss()

 

arrow function绑定的是undefined, 因为 

 

posted @ 2022-03-15 13:08  ascertain  阅读(21)  评论(0编辑  收藏  举报