const Component = (function ($) { const initialize = (function () { var isInited = false; function css() { /*content-start .component, .component * { font-family: Arial; font-size: 12px; line-height: 1; color: #4D4D4D; padding: 0px; margin: 0px; } content-end*/ } return function () { if (isInited) return; isInited = true; (function () { const startStr = '/*content-start', endStr = 'content-end*/', fnStr = css.toString(), textStart = fnStr.indexOf(startStr) + startStr.length, textEnd = fnStr.lastIndexOf(endStr), text = fnStr.substring(textStart, textEnd).trim(); $(document.head).append($('<style type="text/css"/>').html(text)); })(); }; })(); return function () { initialize(); this.x = 5; this.y = 10; this.elem = $('<div class="component"/>').text('x = ' + this.x + '; y = ' + this.y); }; })(jQuery);
Source: https://habr.com/ru/post/213009/
All Articles