function add(a,b){
console.log(this);
return a+b;
}
add(10,20)//this===window
var obj={
name:'aaa',
age:20,
said:function(){
console.log(this);
}
}
obj.said();//this===obj,此处this指代被调用者
function School(){
this.said=function(){
console.log(this);
}
}
var nanj=new School();
nanj.said();//对象调用自己的方法,this===nanj,类似上面
function change(a,b){
this.detial=a*b;
console.log(this);
}
var p={};
change.call(p,4,5);//此处的this===p
console.log(p.detial);
var q=[];
change.call(q,5,10)//this===q
console.log(q.detial);
//apply和call一样的用法,只不过apply第二个参数用数组进行传递
var arr=[];
change.apply(arr,[10,10]);//this===arr
console.log(arr.detial);
var str={};
change.apply(str,[20,20]);//this===str
console.log(str.detial);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有