我正在尝试从 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);