一、
call方法 改变this得指向性
.call() 第一个参数 改变得对象 后续参数传入方法对应得参数(参数列表形式进行传入)
apply() 第一参数 改变得对象 第二个参数[ ]放入参数列表(数组方式进行传入)
<script>
function Student(name,age){
this.name=name
this.age=age
}
Student.prototype.show=function(){
console.log(this.name)
}
Student.prototype.abc=function(a,b,c){
console.log(this.name+a+b+c)
}
var s1=new Student("王一",21)
var s2=new Student("王二",22)
s1.abc.call(s2,1,2,3) //王二 123 参数列表形式进行传入
//apply() 第一参数 改变得对象 第二个参数[]放入参数列表
s1.abc.apply(s2,[1,2,3]) // 王二123 数组方式传入
<script>
二、Math.max()用于输出一组数据中最大值
math,max() 只能存参数列表形式,所有我们利用apply() 方法 把它求出
var result=Math.max(2,35,123,33)// 最大为123
console.log(result) (只能是参数列表形式)
var arr=[1,3,4,5]
var result=Math.max.apply(null,arr) //利用apply方法 把最大值求出
console.log(result) //5