toString()方法 和this指向
JavaScript中定义了其中数据类型 Boolean number string undefined null symbol object 除了undefined和null类型外 都有toString() 方法
this的指向
1 严格模式下全局作用域中的this指向window对象
‘use strict’
console.log(this === window) // true
2 严格模式下在全局作用域中函数的this指向undefined ,反之指向window
例子: // 'use strict'
function fn() {
console.log('fn 中的this', this);
function fn2() {
console.log('fn2中的this', this);
}
fn2()
}
fn()