<script>
var a = {
name:'A',
fn:function(){
alert(this.name);
}
}
a.fn();//this===a
a.fn.call({name:"B"});//this==={name:"B"}
var fn1 = a.fn;
fn1();//this===window
</script>
<script>
var a = {
name:'A',
fn:function(){
alert(this.name);
}
}
a.fn();//this===a
a.fn.call({name:"B"});//this==={name:"B"}
var fn1 = a.fn;
fn1();//this===window
</script>
本文标题:this指向
本文链接:https://www.haomeiwen.com/subject/oqufkftx.html
网友评论