Js inheritance function, found somewhere in internet, and adapted as helper function for App object in application.
var App = {}; App.inherit = (function() { function Nothing() { } return function(child, parent) { Nothing.prototype = parent.prototype; child.prototype = new Nothing; child.prototype.constructor = child; child.superproto = parent.prototype; return child; }; })();Simple usage for view and edit modalboxes:
(function($) {'use strict'; /* * SHOW window */ function ModalWindow(options) { // init elements and load content here } ModalWindow.prototype.constructor = ModalWindow; ModalWindow.prototype.close = function() { // close handlers } /* * EDIT window */ function EditModalWindow(options) { // aka parent constructor ModalWindow.call(this, options); // init save functionality , append buttons, handlers... } App.inherit(EditModalWindow, ModalWindow); EditModalWindow.prototype.save = function(e) { // save handler }; App.EditModalWindow = EditModalWindow; App.ModalWindow = ModalWindow; })(jQuery);
var modal = new App.ModalWindow({ // options }); var editModal = new App.EditModalWindow({ // options });