【发布时间】:2013-04-11 02:18:03
【问题描述】:
我正在尝试从 DOM Element 对象继承,当我创建对象时所有代码都运行良好,但是当我尝试调用 appendChild() 方法时,它给出了一个错误提示:
MyObject doesn't have an appendChild method
这是我的代码:
var content=document.createTextNode("This was dynamically created");
function MyObject(tagName){
Element.constructor.call(this,tagName);
this.prototype=Element.prototype;
this.prototype=Object.defineProperties(this.prototype,{
newMethod:function(){
//dosomething
}
});
}
var newObj=new MyObject("div");
newObj.appendChild(content);
【问题讨论】:
标签: javascript dom element prototypal-inheritance