So I am trying to use the Document()
constructor method to create my own document but I fail at Illegal Invocation Error
. Could someone explain this behavior?
mydom = new Document()
// TypeError: Illegal constructor
var MyDom = new Function()
// undefined
MyDom.prototype
// Object {}
MyDom.prototype = Document.prototype
// Document {createElement: function, createDocumentFragment: function, createTextNode: function, createComment: function, createCDATASection: function…}
myowndom = new MyDom()
// Document {createElement: function, createDocumentFragment: function, createTextNode: function, createComment: function, createCDATASection: function…}
myowndom.createElement('h1')
// TypeError: Illegal invocation
Document.prototype.constructor
// function Document() { [native code] }
myowndom.createAttribute.call(Document, "h1")
// TypeError: Illegal invocation