JS-7-new

xiaoxiao2021-02-27  224

function p(){

this.name = "111"

}

var o = {};

p.call(o);

o.name;//111 o.p()     o.name="111"

function Persion(name,age){

this.name = name;

this.age = age;

}

模仿实现new方法

var p1 = new Person("cd",22)

function New(f){ // f 是个构造器函数

return function(){

var o = {"__proto__":f.prototype};

f.apply(o.arguments);//o.f();

return o;

}

}

var p2 = New(Person)("xx",33);

转载请注明原文地址: https://www.6miu.com/read-12587.html

最新回复(0)