{"id":292197,"date":"2019-07-17T15:01:50","date_gmt":"2019-07-17T15:01:50","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=292197"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=292197","title":{"rendered":"\u0411\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u0442\u0430\u0440\u0442 \u0441 WebComponents"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u0412\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b. \u0412\u0441\u0435 \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432, \u0442.\u0435. \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438\u043b\u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0432 \u043a\u043e\u0434\u0430, \u043e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 Internet Explorer 11, \u0442\u043e \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u043e\u043f\u044b\u0442 \u0441 \u0442\u0435\u043c \u0438\u043b\u0438 \u0438\u043d\u044b\u043c \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c, \u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0444\u043e\u043a\u0443\u0441\u0430\u043c, \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0438 \u043c\u043d\u043e\u0433\u043e\u043e\u043f\u044b\u0442\u043d\u044b\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u0430\u043c.<\/p>\n<p>  \u0412\u0441\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b\u0438\u0441\u044c \u0432 Chrome \u0438 Firefox \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0430\u0436\u0435 \u043d\u0435 \u0441\u0430\u043c\u044b\u0445 \u043d\u043e\u0432\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u0439.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u0442\u0430\u043a \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0432 \u043d\u0435\u0433\u043e.<\/p>\n<pre><code class=\"bash\">mkdir mywebcomp cd mywebcomp <\/code><\/pre>\n<p>  \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c: <\/p>\n<pre><code class=\"bash\">npm init  <\/code><\/pre>\n<p>  \u0432 \u044d\u0442\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u0432 \u043d\u0430 \u0432\u0441\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0444\u0430\u0439\u043b <b>index.html <\/b> \u0441 \u0441\u0430\u043c\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c.<\/p>\n<pre><code class=\"xml\">&lt;html lang=\"en\"&gt;  &lt;body&gt;  &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0435\u0433 \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0438\u043c\u044f \u0434\u043e\u043b\u0436\u043d\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u0435\u0444\u0438\u0441, \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b CusomElements \u0434\u043b\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a\u0430\u043a \u043d\u0430\u0434\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435.<\/p>\n<pre><code class=\"xml\">&lt;html lang=\"en\"&gt;  &lt;body&gt;  &lt;my-webcomp&gt;&lt;\/my-webcomp&gt;  &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u0442\u0435\u0433\u0435 <b>script<\/b>.<\/p>\n<pre><code class=\"javascript\">&lt;script type=\"module\"&gt;    class MyWebComp extends HTMLElement {        connectedCallback() {            this.insertAdjacentHTML('beforeEnd', `&lt;div&gt;Hello&lt;\/div&gt;`)        }    }    customElements.define('my-webcomp', MyWebComp); &lt;\/script&gt; <\/code><\/pre>\n<p>  \u0412 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u043c \u0442\u0435\u0433\u0435 <b>script<\/b>, \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 c \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <b>customElements.define()<\/b> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0437\u0430 \u0442\u0435\u0433\u043e\u043c <b>my-webcomp<\/b>. \u0410 \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043a\u043e\u0434 \u0432 \u043c\u0435\u0442\u043e\u0434 <b>connectedCallback()<\/b> \u043c\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u043b\u0438 \u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u043e. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/h8\/pe\/qv\/h8peqvzesjscex546s9he2xndqc.png\"><\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c html \u0432\u0435\u0440\u0441\u0442\u043a\u0443 \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u0434 \u0435\u0441\u043b\u0438 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043a\u0443\u0441\u043e\u0447\u043a\u043e\u0432, \u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 \u043a\u0443\u0441\u043e\u0447\u043a\u0438 \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0434\u043e \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0444\u043e\u0440\u043c\u0435 \u0441 20\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u0431\u0438\u0442\u044c \u043d\u0430 \u043f\u043e\u0434\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0442\u043e\u0436\u0435 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0432\u0435\u0440\u0441\u0442\u043a\u0443 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 html, \u0445\u043e\u0442\u044f \u043d\u0438\u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u0448\u0430\u0435\u0442 \u0435\u0433\u043e \u043d\u0430\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. <\/p>\n<pre><code class=\"xml\">&lt;html lang=\"en\"&gt;  &lt;body&gt;  &lt;template id=\"myWebCompTemplate\"&gt;    &lt;div&gt;Hello&lt;\/div&gt; &lt;\/template&gt;  &lt;my-webcomp&gt;&lt;\/my-webcomp&gt;  &lt;script type=\"module\"&gt;    class MyWebComp extends HTMLElement {        connectedCallback() {            let tplEl = document.querySelector('#myWebCompTemplate');            let html = document.importNode(tplEl.content, true);            this.appendChild(html);        }    }    customElements.define('my-webcomp', MyWebComp); &lt;\/script&gt;  &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u0434\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 c html \u043c\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u043b\u0438 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u043e id. \u0418\u043c\u043f\u043e\u0440\u0442, \u0442.\u0435. \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043f\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438 \u043f\u0440\u0438\u0446\u0435\u043f\u043b\u0435\u043d\u0438\u0435 \u043a \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u043c\u0443 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e.<\/p>\n<p>  id \u043d\u0430\u0437\u0432\u0430\u043d \u0432 \u043d\u043e\u0442\u0430\u0446\u0438\u0438 camelCase \u0442.\u043a. \u0432\u0441\u0435 \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0435\u043d \u0438 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0435\u0444\u0438\u0441\u043e\u0432 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043f\u0435\u0446. \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0438\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u0435\u043d\u0435\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u0435\u043d. \u0422.\u0435. \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u043c\u0435\u0441\u0442\u043e: <\/p>\n<pre><code class=\"javascript\">           let tplEl = document.querySelector('#myWebCompTemplate');            let html = document.importNode(tplEl.content, true); <\/code><\/pre>\n<p>  \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443: <\/p>\n<pre><code class=\"javascript\">let html = document.importNode(myWebCompTemplate.content, true); <\/code><\/pre>\n<p>  \u0438 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0431\u044b \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043d\u043e \u044d\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c. \u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u043c id \u043d\u0430\u0448\u0435\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443, \u0442\u043e \u0441\u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u043c\u0443 \u0438\u0437 \u043b\u044e\u0431\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u0430\u043a \u043a \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0443 \u0438\u0437 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432. <br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"xml\">&lt;my-webcomp id=\"myWebComp\"&gt;&lt;\/my-webcomp&gt;  &lt;script type=\"module\"&gt;    class MyWebComp extends HTMLElement {        connectedCallback() {            let html = document.importNode(myWebCompTemplate.content, true);            this.appendChild(html);        }    }    customElements.define('my-webcomp', MyWebComp); &lt;\/script&gt; &lt;script type=\"module\"&gt;    myWebComp.showMessage(); &lt;\/script&gt; <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u0435 \u0430\u043b\u0435\u0440\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0432\u0435\u0441\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043a\u043b\u0438\u043a\u0430 \u043c\u044b\u0448\u043a\u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0430\u043b\u0435\u0440\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"xml\">&lt;my-webcomp id=\"myWebComp\" onclick=\"this.showMessage(event)\"&gt;&lt;\/my-webcomp&gt;  &lt;script type=\"module\"&gt;    class MyWebComp extends HTMLElement {        connectedCallback() {            let html = document.importNode(myWebCompTemplate.content, true);            this.appendChild(html);        }        showMessage(event) {            alert(\"This is the message\");            console.log(event);        }    }    customElements.define('my-webcomp', MyWebComp); &lt;\/script&gt; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ps\/vc\/pc\/psvcpclb5o5nlzbhfqxvweozoda.png\"><\/p>\n<p>  \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430 <b>showMessage()<\/b> \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <b>event<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043a\u043b\u0438\u043a\u0430 \u0438\u043b\u0438 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0430\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<p>  \u0427\u0430\u0441\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0434\u043e \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <b>greet-name<\/b> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<pre><code class=\"xml\">&lt;my-webcomp id=\"myWebComp\" greet-name=\"John\" onclick=\"this.showMessage(event)\"&gt;&lt;\/my-webcomp&gt; &lt;my-webcomp id=\"myWebComp2\" greet-name=\"Josh\" onclick=\"this.showMessage(event)\"&gt;&lt;\/my-webcomp&gt; &lt;script type=\"module\"&gt;    class MyWebComp extends HTMLElement {        connectedCallback() {            let html = document.importNode(myWebCompTemplate.content, true);            this.appendChild(html);        }        showMessage(event) {            alert(\"This is the message \" + this.getAttribute('greet-name'));            console.log(event);        }    }    customElements.define('my-webcomp', MyWebComp); &lt;\/script&gt; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u201cThis is the message for John\u201d, \u0430 \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u201cThis is the message for Josh\u201d. <\/p>\n<p>  \u041c\u043e\u0436\u0435\u0442 \u0442\u0430\u043a \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0447\u0442\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0430 \u043f\u0440\u044f\u043c\u043e \u043e\u0442\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0432 \u0448\u0430\u0431\u043b\u043e\u043d, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c id \u0446\u0435\u043b\u0435\u0432\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u0430\u043f\u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u043a\u043e\u043f\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u0430.<\/p>\n<pre><code class=\"xml\">&lt;template id=\"myWebCompTemplate\"&gt;    &lt;div id=\"helloLabel\"&gt;Hello&lt;\/div&gt; &lt;\/template&gt;  &lt;my-webcomp id=\"myWebComp\" greet-name=\"John\" onclick=\"this.showMessage(event)\"&gt;&lt;\/my-webcomp&gt; &lt;my-webcomp id=\"myWebComp2\" greet-name=\"Josh\" onclick=\"this.showMessage(event)\"&gt;&lt;\/my-webcomp&gt;  &lt;script type=\"module\"&gt;    class MyWebComp extends HTMLElement {        connectedCallback() {            let html = document.importNode(myWebCompTemplate.content, true);            this.appendChild(html);            this.querySelector('#helloLabel').textContent += ' ' + this.getAttribute('greet-name');        }        showMessage(event) {            alert(\"This is the message \" + this.getAttribute('greet-name'));            console.log(event);        }    }    customElements.define('my-webcomp', MyWebComp); &lt;\/script&gt; <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/xs\/gr\/it\/xsgrity3vcy4h9olcpuppvcupl0.png\"><\/p>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e <b>.textContent<\/b> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c <b>.innerHTML<\/b> \u0438\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u0437 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430 \u0442\u043e\u0442 \u0436\u0435 \u043c\u0435\u0442\u043e\u0434 <b>.insertAdjacentHTML()<\/b> \u043c\u044b \u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435.<\/p>\n<p>  \u0414\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a\u043e\u0432 \u0441\u0447\u0438\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u0443\u0440\u043d\u044b\u043c \u0442\u043e\u043d\u043e\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043c\u0430\u0445 \u043a\u043e\u0434\u0430 \u043e\u043d\u0438 \u043c\u043e\u0433\u043b\u0438 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u043e \u043a \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u044f\u043c. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0442\u0435\u043d\u0435\u0432\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a\u0438, \u0441\u0442\u0438\u043b\u0438 \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0431\u0435\u0437 \u043e\u043f\u0430\u0441\u0435\u043d\u0438\u0439. \u0414\u043b\u044f \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043d\u0435\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">           this.attachShadow({mode: 'open'}); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0430\u0432\u0434\u0430 \u0432\u0441\u0435 DOM \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a this \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 <b>this.shadowRoot<\/b> \u0431\u043b\u0430\u0433\u043e \u0438\u0445 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e. <\/p>\n<pre><code class=\"xml\">&lt;script type=\"module\"&gt;    class MyWebComp extends HTMLElement {        connectedCallback() {            let html = document.importNode(myWebCompTemplate.content, true);            this.attachShadow({mode: 'open'});            this.shadowRoot.appendChild(html);            this.shadowRoot.querySelector('#helloLabel').textContent += ' ' + this.getAttribute('greet-name');        }        showMessage(event) {            alert(\"This is the message \" + this.getAttribute('greet-name'));            console.log(event);        }    }    customElements.define('my-webcomp', MyWebComp); &lt;\/script&gt; <\/code><\/pre>\n<p>  \u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043e\u043f\u044f\u0442\u044c \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0438\u043c\u0435\u043d \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e helloLabel, \u0430 \u0443 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0443\u0436\u0435 2 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441 \u0442\u0430\u043a\u0438\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c. \u0410 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">myWebComp.shadowRoot.getElementById('helloLabel'); <\/code><\/pre>\n<p>  \u0438 \u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u0430\u043a\u0440\u043e\u0435\u0442\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <b>.attachShadow()<\/b>. <\/p>\n<p>  \u0423 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u0440\u044f\u043c\u043e \u0432 html \u0444\u0430\u0439\u043b\u0435 \u0442\u043e\u0436\u0435 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <b>my-webcomp.js <\/b> \u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439 export, \u0430 \u0432 \u0442\u0435\u0433\u0435 script \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u043c\u043f\u043e\u0440\u0442 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0435:<\/p>\n<pre><code class=\"xml\">&lt;script type=\"module\"&gt;    import { MyWebComp } from \".\/my-webcomp.js\";     customElements.define('my-webcomp', MyWebComp);    myWebComp.shadowRoot.getElementById('helloLabel'); &lt;\/script&gt; <\/code><\/pre>\n<p>  \u041d\u0430 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u044d\u0442\u043e \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0441\u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u044f \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0430 \u0443 \u043d\u0430\u0441 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432 .js, \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 html \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u0430 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u0443\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0431\u0435\u0440\u0443\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0439 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430.<\/p>\n<p>  \u041f\u0440\u0430\u0432\u0434\u0430 \u0441 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c <b>index.html<\/b> \u043a\u0430\u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f, \u0442.\u043a. \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c nodejs \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440:<\/p>\n<pre><code class=\"bash\">npm i http-server -g <\/code><\/pre>\n<p>  \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 http-server \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c, \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043e\u043d \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442 \u0445\u043e\u0441\u0442 \u0438 \u043f\u043e\u0440\u0442 \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443<\/p>\n<pre><code class=\"bash\">http:\/\/127.0.0.1:8080  <\/code><\/pre>\n<p>  \u041a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043d\u044b\u043d\u0435 \u0430\u0434\u0440\u0435\u0441\u043e\u043c \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441 \u043d\u0430\u0448\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c.<\/p>\n<p>  \u041d\u0435\u043c\u0430\u043b\u043e\u0432\u0430\u0436\u043d\u044b\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432, \u043e\u043d\u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u043c \u0432 \u0445\u043e\u0434\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c mocha \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0430\u043a\u0435\u0442\u044b.<\/p>\n<pre><code class=\"bash\">npm i mocha chai wct-mocha --save-dev <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <b>test<\/b> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u0444\u0430\u0439\u043b <b>all.html<\/b> \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e:<\/p>\n<pre><code class=\"xml\">&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt;    &lt;meta charset=\"utf-8\"&gt;    &lt;script src=\"..\/node_modules\/mocha\/mocha.js\"&gt;&lt;\/script&gt;    &lt;script src=\"..\/node_modules\/chai\/chai.js\"&gt;&lt;\/script&gt;    &lt;script src=\"..\/node_modules\/wct-mocha\/wct-mocha.js\"&gt;&lt;\/script&gt; &lt;\/head&gt; &lt;body&gt;  &lt;script&gt;     WCT.loadSuites([        'my-webcomp.tests.html',    ]);  &lt;\/script&gt; &lt;\/body&gt; &lt;\/html&gt; <\/code><\/pre>\n<p>  \u0421\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 <b>index.html<\/b> \u0432 <b>test\/<\/b> \u0437\u0430\u0434\u0430\u0432 \u0435\u043c\u0443 \u0438\u043c\u044f <b>my-webcomp.tests.html<\/b> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 head \u043a\u0430\u043a \u0438 \u0432 <b>all.html<\/b>.<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0430\u043c \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c\u0443\u044e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<pre><code class=\"xml\">&lt;script type=\"module\"&gt;    import { MyWebComp } from \"..\/my-webcomp.js\";     customElements.define('my-webcomp', MyWebComp);    suite('MyWebComp', () =&gt; {        test('is MyWebComp', () =&gt; {            const element = document.getElementById('myWebComp');            chai.assert.instanceOf(element, MyWebComp);        });    }); &lt;\/script&gt; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u0437\u0430\u0445\u043e\u0434\u0435 \u043d\u0430<\/p>\n<pre><code class=\"bash\">http:\/\/127.0.0.1:8080\/test\/all.html <\/code><\/pre>\n<p>  \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043e\u0442\u0447\u0435\u0442 \u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/_7\/ub\/ok\/_7ubokve7hcudxp_djz5yecpkf8.png\"><\/p>\n<p>  \u041d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u0443:<\/p>\n<pre><code class=\"bash\">sudo npm install --global web-component-tester --unsafe-perm <\/code><\/pre>\n<p>  \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a: <\/p>\n<pre><code class=\"bash\">wct --npm <\/code><\/pre>\n<p>  \u042d\u0442\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u0435\u043a\u0446\u0438\u044e <b>test<\/b> \u0444\u0430\u0439\u043b\u0430 <b>package.json<\/b> \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u0430\u043a:<\/p>\n<pre><code class=\"bash\">npm test <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/la\/_e\/rp\/la_erpwvp142hir0gnvg21fgchg.png\"><\/p>\n<p>  \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430. \u0415\u0441\u043b\u0438 \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0449\u0443\u044e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <b>suiteSetup()<\/b>:<\/p>\n<pre><code class=\"javascript\">suiteSetup(() =&gt; {  }); <\/code><\/pre>\n<p>  \u0432\u043d\u0443\u0442\u0440\u0438 suite.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u0430\u0437\u0430, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0440\u0435\u0448\u0430\u0439 \u043e\u043d \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0435 \u0441\u0442\u044b\u0434\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<pre><code class=\"bash\">npm publish  <\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b<\/p>\n<pre><code class=\"bash\">git push <\/code><\/pre>\n<p>  \u041a\u043d\u0438\u0433 \u043d\u0430 \u0442\u0435\u043c\u0443 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0442\u0430\u043a \u0443\u0436 \u043c\u043d\u043e\u0433\u043e, \u043d\u043e \u0432\u0441\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u043e\u0432\u0430\u043c Web Components, CustomElements, ShadowDOM, Native Template Tag, Custom Events.<\/p>\n<p>  \u0421\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u043c: <a href=\"https:\/\/bitbucket.org\/techminded\/mywebcomp\">https:\/\/bitbucket.org\/techminded\/mywebcomp<\/a><\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/460397\/\"> https:\/\/habr.com\/ru\/post\/460397\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u0412\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b. \u0412\u0441\u0435 \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432, \u0442.\u0435. \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438\u043b\u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0432 \u043a\u043e\u0434\u0430, \u043e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 Internet Explorer 11, \u0442\u043e \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u043e\u043f\u044b\u0442 \u0441 \u0442\u0435\u043c \u0438\u043b\u0438 \u0438\u043d\u044b\u043c \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c, \u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0444\u043e\u043a\u0443\u0441\u0430\u043c, \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0438 \u043c\u043d\u043e\u0433\u043e\u043e\u043f\u044b\u0442\u043d\u044b\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u0430\u043c.<\/p>\n<p>  \u0412\u0441\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u043b\u0438\u0441\u044c \u0432 Chrome \u0438 Firefox \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0430\u0436\u0435 \u043d\u0435 \u0441\u0430\u043c\u044b\u0445 \u043d\u043e\u0432\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u0439.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-292197","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292197"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/292197\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}