创建一个对象:
function Person(name) {
this.name = name;
}
var p = new Person("xiaohu");
new的实现:
var obj = {};
obj.__proto__ = Person.prototype;
var result = Person.call(obj,"hester");
return typeof result === 'obj'? result : obj;
function Person(name) {
this.name = name;
}
var p = new Person("xiaohu");
var obj = {};
obj.__proto__ = Person.prototype;
var result = Person.call(obj,"hester");
return typeof result === 'obj'? result : obj;
本文标题:javascript new的实现
本文链接:https://www.haomeiwen.com/subject/wuwexftx.html
网友评论