liujinyu

1、Function.apply,用于构造函数的继承,继承另外一个构建对象的属性与方法

function People(name,age){
    this.name = name;
    this.age = age;
}

function Student(age){
    this.age = age;
    People.apply(this,arguments)
}
var stu = new Student(\'liujinyu\',\'12\');
var peo = new People(\'liujinyu\',\'12\')
console.log( stu)  //{age:"12",name:"liujinyu"}
console.log(peo)   //{name:"liujinyu",age:"12"  }

 

2、用于调用函数,传参。传一个数组进去,形参会逐一匹配数组中的元素。

function peo(name,age){
    console.log(name,age);
}
var arr = [[\'liu\',\'12\'],[\'jin\',\'13\'],[\'yu\',\'14\']];
$.each(arr,function(i,v){
   peo.apply(null,v);
    //peo(v[0],v[1]);   //等同效果
})
//输出结果
//liu 12
//jin 13
//yu 14

分类:

技术点:

相关文章:

  • 2021-12-13
  • 2021-12-19
  • 2021-12-19
  • 2018-04-13
  • 2022-01-07
  • 2021-08-22
猜你喜欢
  • 2021-12-19
  • 2022-01-23
  • 2021-12-19
  • 2021-12-19
  • 2021-12-19
  • 2022-03-09
  • 2021-11-10
相关资源
相似解决方案