Function.prototype.myApply = function (context) {
var context = context || window
context.fn = this
var args = [...arguments].slice(1)
if (!args) {
var result = context.fn()
} else {
var result = context.fn(...args[0])
}
delete context.fn
return result
}
function People(name,age){
this.name=name
this.age=age
this.sayName=function(){
console.log(arguments)
console.log(this.name+' '+this.age)
}
}
function Stu(name,age){
this.name=name
this.age=age
}
var obj={
name:'xiaozhang',
age:1,
sayName:function(name,age){
this.name=name
this.age=age
console.log(this.name+' '+this.age)
}
}
var stu=new Stu("tom1",18)
var people=new People("mary",20)
people.sayName.myApply(stu,["jerry",14])
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。