簡體   English   中英

創建自己的文檔Javascript

[英]Creating own Document Javascript

因此,我嘗試使用Document()構造函數方法來創建自己的文檔,但是在Illegal Invocation Error失敗。 有人可以解釋這種行為嗎?

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

不打算調用Document函數 ,而只是將其用作方便變量。 文檔是宿主對象(具有非常復雜的基礎API),並且不容易構造。

如果要創建一個額外的Document實例,則可以使用document.implementation.createDocument()方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM