JS題の印刷結果
864 ワード
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