From 0de177003a457e8748f6f3ffd1e1d7778bad7fdc Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 23 Sep 2015 18:13:38 +0200 Subject: [PATCH] Add Core.inherit() --- wcfsetup/install/files/js/WoltLab/WCF/Core.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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. * -- 2.20.1