Instantiating new HTMLElement in TypeScript
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to instantiate new HTMLDivElement in TypeScript var elem = new HTMLDivElement(); but the browser throws Uncaught TypeError: Illegal constructor. The workaround seems to be to use var elem = document.createElement('div'); but I find this suboptimal for various reasons. Why can't I instantiate DOM elements directly when there is a new keyword for in in the lib.d.ts ? declare var HTMLDivElement: { prototype: HTMLDivElement; new (): HTMLDivElement; } 回答1: Note that the error you get here is "Illegal constructor". This is different