所以我試圖使用Document()
構造函數方法來創建我自己的文檔,但我在Illegal Invocation Error
失敗。有人可以解釋這種行爲嗎?創建自己的文檔Javascript
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
可能的重複http://stackoverflow.com/questions/8227612/how-to-create-document-objects-with-javascript – leorex
我見過這個問題。我的問題不同,因爲它專注於原型鏈。 – sudo
您不打算調用Document函數。檢查最新的答案,幾乎與我的評論相同。 – leorex