[英]How to instantiate a <code></code> element in JavaScript (NodeJS)?
TheHTMLPreElement
type in JavaScript produces a DOM element corresponding to the <pre>
tag. JavaScript 中的HTMLPreElement
类型产生一个对应于<pre>
标签的 DOM 元素。 Where is the type corresponding to <code>
? <code>
对应的类型在哪里? It seems there should be an HTMLCodeElement
type, but there isn't.似乎应该有一个HTMLCodeElement
类型,但没有。 How do I go about instantiating this in NodeJS JavaScript?我如何 go 关于在 NodeJS JavaScript 中实例化它?
const c0d3 = document.createElement("code");
Object.getPrototypeOf(c0d3).constructor.toString();
//function(){return a.Reflect.construct(a.HTMLElement,[],this.constructor)}
At least on the browser side (Chrome, on node side you possibly have other workarounds to create mock DOM elements), it is not directly a distinct constructor, but rather a wrapper function that makes use of HTMLElement
itself and another function this.constructor
that is passed as an argument to Reflect.construct .至少在浏览器端(Chrome,在节点端,您可能有其他解决方法来创建模拟 DOM 元素),它不是直接的独特构造函数,而是使用HTMLElement
本身和另一个 function this.constructor
的包装器 function作为参数传递给Reflect.construct 。
The old way of creating these native constructors are generally something like:创建这些原生构造函数的旧方法通常是这样的:
//Instances inherit from parent proto
HTMLSomeChildElementFunc.prototype = Object.create(HTMLSomeParentElementFunc.prototype);
//Statics are inherited on the constructor
Object.setPrototypeOf(HTMLSomeCHildElement, HTMLSomeParentElement);
In this case it is a bit different, they went for some sort of monkey patch.在这种情况下,它有点不同,他们选择了某种猴子补丁。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.