ООП JavaScript - Создать пользовательский объект Div
Я только начинаю с ООП в JavaScript. Я хочу создать собственную & quot; панель. & Quot; Вот что у меня так далеко:
function ShinyPanel(css, attributes)
{
this.container = $(document.createElement("div")).addClass("shinyPanel");
this.titleBar = $(document.createElement("div")).addClass("shinyPanelTitleBar").appendTo(this.container);
this.topShine = $(document.createElement("div")).addClass("shinyPanelTopShine").appendTo(this.container);
this.leftShine = $(document.createElement("div")).addClass("shinyPanelLeftShine").appendTo(this.container);
this.content = $(document.createElement("div")).addClass("shinyPanelContent").appendTo(this.container);
if (!css) css = {};
if (!attributes) attributes = {};
this.css = css;
$(this.container).css(this.css);
this.title = attributes["title"];
$(this.titleBar).html(this.title);
}
Теперь я могу создать экземпляр этого объекта и добавить его к телу примерно так:
var panel = new ShinyPanel({position:"absolute", top:"25%", width:"300px", height:"200px"}, {title:"Test"});
$("body").append(panel.container);
Мой вопрос заключается в том, есть ли для меня способ сделать сам объект div, что устраняет необходимость в «контейнере»; DIV? Тогда я мог бы просто позвонить$("body").append(panel);
.
Для меня не так уж сложно иметь там контейнер div, это больше просто для меня ... желая узнать, как правильно делать вещи.
Я старалсяthis = document.createElement("div");
, но я получил ошибку:invalid assignment left-hand side
.