1
的index.html與ECMA6
<!DOCTYPE html>
<html>
<head>
<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
<script>
traceur.options.experimental = true;
</script>
<link rel="import" href="x-item.html">
</head>
<body>
<x-item></x-item>
</body>
</html>
Web組件和我的web組件: X-item.html
<template id="itemtemplate">
<span>test</span>
</template>
<script type="module">
class Item extends HTMLElement {
constructor() {
let owner = document.currentScript.ownerDocument;
let template = owner.querySelector("#itemtemplate");
let clone = template.content.cloneNode(true);
let root = this.createShadowRoot();
root.appendChild(clone);
}
}
Item.prototype.createdCallback = Item.prototype.constructor;
Item = document.registerElement('x-item', Item);
</script>
,我沒有錯誤,也沒有我期待什麼被顯示,任何想法,如果這應該實際上工作?
這是如何在ECMA6語法中擴展HTMLElement的?
è:把它完全在一個頁面至少現在我知道它創建一個自定義組件以正確的方式解決問題,但問題是有它在一個單獨的文件,我認爲這與該怎麼辦traceur句柄<link rel="import" href="x-item.html">
我試着將類型屬性添加到導入中,但沒有運氣。
而你期望顯示的是......什麼?尋求調試幫助的問題(「**爲什麼不是這個代碼工作?」)必須包括所需的行爲,*特定的問題或錯誤*以及*在問題本身中重現它所需的最短代碼* *。沒有**明確問題陳述**的問題對其他讀者沒有用處。請參閱:[如何創建一個最小,完整和可驗證的示例。](http://stackoverflow.com/help/mcve) –
@EdCottrell測試 – user1492051
「任何想法,如果這實際上應該工作?」我認爲我們不知道,直到我們有一個符合兩個規範的實施。 – BoltClock