Created
May 11, 2017 09:54
-
-
Save porqz/0666d130d8da41a2fe2039025cabb1de to your computer and use it in GitHub Desktop.
Simple JavaScript inheritance implementation (my old code)
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
(function () { | |
var defaults = { | |
defaultsPropertyName: "defaults" | |
}; | |
/** | |
* Реализует простое наследование | |
* | |
* @param {Function} constructor Функция-конструктор класса-родителя | |
* @param {?Object} prototype Объект, который будет использован в качестве прототипа для потомка | |
* | |
* @return {Object} Функция-конструктор класс-потомка | |
*/ | |
Function.prototype.inheritFrom = Function.prototype.inheritFrom || function (constructor, prototype) { | |
var intermediateFunction = function () {}; | |
intermediateFunction.prototype = constructor.prototype; | |
this.prototype = new intermediateFunction(); | |
this.prototype.constructor = this; | |
if (typeof prototype != "undefined") { | |
for (var propertyName in prototype) { | |
this.prototype[propertyName] = prototype[propertyName]; | |
if (propertyName == defaults.defaultsPropertyName) { | |
ObjectUtils.extend(this.prototype[propertyName], constructor.prototype[propertyName], function (propertyName, propertyValue, newPropertyValue) { | |
return propertyValue; | |
}); | |
} | |
} | |
} | |
this.superprototype = constructor.prototype; | |
return this; | |
}; | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment