var a = 1
function Fn1() {
var a = 2
alert(this.a + a)
}
function Fn2() {
var a = 10
Fn1()
}
Fn2() // 3 --- this.a 在window中获取;a在定义时的作用域中获取
var Fn3 = function() {
this.a = 3
}
Fn3.prototype = {
a: 4
}
var fn3 = new Fn3()
Fn1.call(fn3) // 5 --- fn3 是 {a: 3},this.a已在本身获取,不去原型链上找;a在定义时的作用域中获取
console.log(num)
function num() {} // f num()
console.log(num)
var num // undefined
(function(num) {
console.log(num)
function num() {}
})(100) // f num()
(function(num) {
console.log(num)
var num
})(100) // 100
var num = 100
var foo = {
num: 200,
bar: {
num: 300,
print: function() {
console.log(this.num);
}
}
}
foo.bar.print() // 300
let f = foo.bar.print
f() // 100
foo.bar.print.bind(foo)() // 200