function Person(age) { this.age = age; } Person.prototype.sayHi = function (x, y) { console.log((x + y) + ":====>" + this.age); //是实例对象 }; function Student(age) { this.age = age; } var per = new Person(10); //实例对象 var stu = new Student(100); //实例对象 //sayHi方法是per实例对象的 per.sayHi.apply(stu, [10, 20]);//30:====>100 per.sayHi.call(stu, 10, 20);//30:====>100
function Person(age) { this.age=age; } Person.prototype.play=function () { console.log(this+"====>"+this.age); }; function Student(age) { this.age=age; } var per=new Person(10); var stu=new Student(20); //复制了一份 var ff=per.play.bind(stu); ff();
原文:https://www.cnblogs.com/wanguofeng/p/10725032.html