Untitled
unknown
plain_text
4 years ago
1.2 kB
10
Indexable
window.addEventListener("DOMContentLoaded", init);
function SuperButton(tuzik) {
var that = this; // that сохроняет контекст В нашем случае указатель на обьект кнопки
this.name = tuzik;
this.show = function() {
document.body.appendChild(this.buttonEl);
}
// __подчоркивания говорит эта функция используется только внутри конструктора (внутренняя)
this.init_ = function() {
this.buttonEl = addEventListener("click" this.buttonClick_);
}
this.buttonClick_ = function() {
console.log(that.name);
console.log(that, that);
}
this.init_ = function() {
this.buttonEl = document.createElement("div");
this.buttonEl.className = "abc-button";
var textNode = document.createTextNode(this.name);
this.buttonEl.appendChild(textNode);
}
// подпишемся на события
this.attachEvents_();
}
this.init_();
}
function init()
{
var button = new SuperButton("Кнопка");
button.show();
}
Editor is loading...