所有的对象都拥有proto属性,它指向对象构造函数的 prototype 属性 let obj={} obj._proto_=Object.prototype/true function Test(){} test._proto_=Test.prototype/true ...Object.prototype._proto_/null
function Father(name){this.name=name;} Father.prototype.setName=function(name){this.name=name;} function Son(name,age){ Father.call(this,name)...Son.prototype._proto_=Father.prototype;Son._proto_=Father;
function Base(){ } Base.prototype.say=function(){ console.log(1);...todo:不使用_proto_调用base.say();say.call(this);console.log('2');} })() var son=new Sub();son.say()/Expect:log:1,2;
function Base(){ } Base.prototype.say=function(){ console.log(1);...todo:不使用_proto_调用base.say();console.log('2');} var son=new Sub();son.say()/Expect:log:1,2;请问有什么方式可以实现吗?
res._proto_=func.prototype;} var ret=func.apply(res,Array.prototype.slice.call(arguments,1));if((typeof ret="object"|typeof ret="function")&ret!null){ return;ret;} return;res;} var obj=New(A,1,2);...
obj._proto_=Con.prototype let result=Con.apply(obj,arguments) return result instanceof Object?result:obj } 以下是对实现的分析: 创建一个空对象获取构造函数设置空对象的原型绑定 this 并执行构造函数确保...