Skip to content

Instantly share code, notes, and snippets.

@restlessmedia
Created July 2, 2015 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save restlessmedia/56c0798a5f95abb52a6b to your computer and use it in GitHub Desktop.
Save restlessmedia/56c0798a5f95abb52a6b to your computer and use it in GitHub Desktop.
extend.js
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;
};
@restlessmedia
Copy link
Author

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment