Вот полный код: -
class code extends HTMLElement{
constructor(){
super();
const shadow = this.attachShadow({
mode: 'open'
});
const code = document.createElement('code');
code.textContent = super.textContent;
shadow.appendChild(code);
}
}
var Ω = (function() {
'use strict';
/**
* Create the constructor
* @param {String} selector The selector to use
*/
var Constructor = function(selector) {
if (!selector) return;
if (selector === 'document') {
this.elems = [document];
} else if (selector === 'window') {
this.elems = [window];
} else {
this.elems = document.querySelectorAll(selector);
}
};
/**
* Run a callback on each item
* @param {Function} callback The callback function to run
*/
Constructor.prototype.each = function(callback) {
if (!callback || typeof callback !== 'function') return;
for (var i = 0; i < this.elems.length; i++) {
callback(this.elems[i], i);
}
return this;
};
Constructor.prototype.register = function(className) {
this.each(function(item) {
customElements.define(item.tagName.toLowerCase(), className);
});
return this;
};
Constructor.prototype.css = function(style){
this.each(function(item) {
item.style.cssText = style;
});
return this;
}
Constructor.prototype.value = function(){
this.each(function(item) {
const val = item.value;
return val;
});
return this;
}
Constructor.prototype.load = function(fn){
window.onload = fn;
return fn;
}
/**
* Instantiate a new constructor
*/
var instantiate = function(selector) {
return new Constructor(selector);
};
/**
* Return the constructor instantiation
*/
return instantiate;
})();
Ω('lol-bar').register(code);
Ω('check-1').register(code);
<lol-bar>Hey</lol-bar><br />
<check-1>This should look like the above one</check-1>
Я ожидал, что это выведет оба тега lol-bar и check-1 в одном формате, но эта штука косвенно говорит, что мне разрешено использоватьконструктор только один раз и, следовательно, дальнейшие определения не могут войти в реальность.Кто-нибудь, пожалуйста, решите это и вытащите меня из этого парадокса.Помощь и ответы приветствуются.Очень помог бы в разработке custags.js , моего проекта с открытым исходным кодом.