JS语法_其他

严格模式

let obj = {
  name: 'oceans',
}
function f1() {
  with (obj) {
    console.log(name)
  }
}
function f2() {
  'use strict'
  // try catch无法捕获
  with (obj) {
    console.log(name)
  }
}
f1()
f2()

this 必须被赋值

// log
function f1() {
  'use strict'
  console.log(this)
}
function f2() {
  console.log(this.innerWidth)
}

f1()
f2()
posted @ 2020-08-28 00:59  oceans-pro  阅读(61)  评论(0编辑  收藏  举报