Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Interface() {}
- /**
- * Implements an interface.
- * @param {Object} implementation The interface implementation.
- * @param {Array<Object>} interfaces The implemented interfaces.
- */
- Interface.implements = function(implementation, interfaces) {
- interfaces = Array.prototype.slice.call(arguments, 1);
- window.addEventListener('load', function() {
- for (var i = 0, interface; interface = interfaces[i]; i++) {
- var properties = Object.keys(interface.prototype);
- for (var j = 0, property; property = properties[j]; j++) {
- var interfaceProperty = interface.prototype[property];
- var implementationProperty = implementation.prototype[property];
- if (typeof interfaceProperty === 'function' &&
- (typeof implementationProperty !== 'function' ||
- implementationProperty.length !== interfaceProperty.length)) {
- throw new Error('Abstract method ' + property + ' is not overriden');
- } else {
- implementation.prototype[property] = interfaceProperty;
- }
- }
- }
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement