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
时间: 2024-10-27 04:56:48