Created
July 2, 2015 10:23
-
-
Save restlessmedia/56c0798a5f95abb52a6b to your computer and use it in GitHub Desktop.
extend.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extend = function (members) { | |
var that = this; | |
var extended; | |
if (members && members.constructor) { | |
extended = members.constructor; | |
} else { | |
extended = function () { | |
return parent.apply(this, arguments); | |
}; | |
} | |
var Surrogate = function () { | |
this.constructor = extended; | |
}; | |
Surrogate.prototype = this.prototype; | |
extended.prototype = new Surrogate; | |
extended.prototype.ctor = function () { | |
return that.apply(this, arguments); | |
}; | |
extended.prototype.base = function (member, args) { | |
return that.prototype[member].apply(this, arguments); | |
}; | |
if (members) { | |
for (var member in members) { | |
if (!members.hasOwnProperty(member)) { | |
continue; | |
} | |
extended.prototype[member] = members[member]; | |
} | |
} | |
return extended; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var template = function () {
'return '
};
var Modal = function (options) {
this.parts = {};
this.className = 'model' + (options.className ? ' ' + options.className : '');
this.initialise();
};
Modal.prototype.show = function () {
console.log('Modal.show()');
};
Modal.prototype.hide = function () {
console.log('Modal.hide()');
};
Modal.prototype.initialise = function () {
this.element = document.createElement('div');
this.element.id = this.id = '_' + new Date().getTime();
this.element.innerHTML = template();
this.element.className = this.className;
document.body.appendChild(this.element);
this.onAttach(this.element);
};
Modal.prototype.onAttach = function (element) {
console.log('Modal.onAttach()');
};
Modal.extend = extend;
var ChromeModal = Modal.extend({
show: function () {
console.log('ChromeModal.show()');
},
initialise: function () {
this.base('initialise');
},
constructor: function () {
this.ctor({className: 'modal-chrome'});
}
});
ChromeModal.extend = extend;