先声明对象a,
function a(){}
向a的原型添加属性和方法
a.prototype={
ss:'xx',
name:function(){console.log(this.ss)}
};
实例化对象a
var na=new a
这时又有一个对象b
b={ss:'00'}
我们想让它借助a的name方法,于是便有了
na.name.call(b)
console.log(b.name)
========================================================
附一个来自知乎的例子:
var Parent = function(){ this.name = "yjc"; this.age = 22; } var child = {}; console.log(child);//Object {} ,空对象 Parent.call(child); console.log(child); //Object {name: "yjc", age: 22}
from:余建材 https://www.zhihu.com/question/20289071/answer/80892838