From: Matthias Schmidt Date: Wed, 23 Sep 2015 16:13:38 +0000 (+0200) Subject: Add Core.inherit() X-Git-Tag: 3.0.0_Beta_1~2120 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0de177003a457e8748f6f3ffd1e1d7778bad7fdc;p=GitHub%2FWoltLab%2FWCF.git Add Core.inherit() --- diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Core.js b/wcfsetup/install/files/js/WoltLab/WCF/Core.js index da79e37438..9ecf991c3b 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Core.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Core.js @@ -113,6 +113,37 @@ define([], function() { return newObj; }, + /** + * Inherits the prototype methods from one constructor to another + * constructor. + * + * @see https://github.com/nodejs/node/blob/7d14dd9b5e78faabb95d454a79faa513d0bbc2a5/lib/util.js#L697-L735 + * @param {function} constructor inheriting constructor function + * @param {function} superConstructor inherited constructor function + * @param {object=} propertiesObject additional prototype properties + */ + inherit: function(constructor, superConstructor, propertiesObject) { + if (constructor === undefined || constructor === null) { + throw new TypeError("The constructor must not be undefined or null."); + } + if (superConstructor === undefined || superConstructor === null) { + throw new TypeError("The super constructor must not be undefined or null."); + } + if (superConstructor.prototype === undefined) { + throw new TypeError("The super constructor must have a prototype."); + } + + constructor._super = superConstructor; + constructor.prototype = Core.extend(Object.create(superConstructor.prototype, { + constructor: { + configurable: true, + enumerable: false, + value: constructor, + writable: true, + } + }), propertiesObject || {}); + }, + /** * Returns true if `obj` is an object literal. *