欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
不同之处是:
 
call() 方法分别接受参数。
 
apply() 方法接受数组形式的参数。
 
如果要使用数组而不是参数列表,则 apply() 方法非常方便。
 
带参数的 apply() 方法
 
apply() 方法接受数组中的参数:
 
实例
 
var person = {
 
  fullName: function(city, country) {
 
    return this.firstName + " " + this.lastName + "," + city + "," + country;
 
  }
 
}
 
var person1 = {
 
  firstName:"John",
 
  lastName: "Doe"
 
}
 
person.fullName.apply(person1, ["Oslo", "Norway"]);
 
与 call() 方法对比:
 
实例
 
var person = {
 
  fullName: function(city, country) {
 
    return this.firstName + " " + this.lastName + "," + city + "," + country;
 
  }
 
}
 
var person1 = {
 
  firstName:"John",
 
  lastName: "Doe"
 
}
 
person.fullName.call(person1, "Oslo", "Norway");

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64475.shtml