Skip to content

Instantly share code, notes, and snippets.

@rochnyak-d-i
Last active August 29, 2015 14:08
Show Gist options
  • Save rochnyak-d-i/4c33418109ce269ace65 to your computer and use it in GitHub Desktop.
Save rochnyak-d-i/4c33418109ce269ace65 to your computer and use it in GitHub Desktop.
JS шаблон абстрактная фабрика
function BluePopup () {
//создание всплывающего окна
}
BluePopup.prototype.attach = function (elemens) {
//присоединение других ui-элементов к окну
}
BluePopupFactory.register('popup', BluePopup);
function BluePopupButton () {
//создание кнопки для синего всплывающего окна
}
BluePopupButton.prototype.setText = function (text) {
//установка текста на кнопке
}
BluePopupFactory.register('button', BluePopupButton);
function BluePopupTitle () {
//создание заголовка для синего окна
}
BluePopupTitle.prototype.setText = function (text) {
//установка текста заголовка
}
BluePopupFactory.register('title', BluePopupTitle);
function UI () {
//класс, отвечающий за ui-элементы
}
UI.createPopup = function (factory) {
var popup = factory.create('popup'),
buttonOk = factory.create('button'),
buttonCancel = factory.create('button'),
title = factory.create('title');
buttonOk.setText('OK');
buttonCancel.setText('Cancel');
title.setText('Untitled');
popup.attach([buttonOk, buttonCancel, title]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment