Comparing version 2.4.0 to 2.5.0
31
index.js
@@ -9,3 +9,3 @@ 'use strict'; | ||
* | ||
* @returns {ChildConstructor} A new constructor, extended from the given context, possibly with some prototype additions. | ||
* @returns {Constructor} A new constructor, extended from the given context, possibly with some prototype additions. | ||
* | ||
@@ -66,2 +66,5 @@ * @desc Extends "objects" (constructors), with optional additional code, optional prototype additions, and optional prototype member aliases. | ||
/** | ||
* @class | ||
*/ | ||
function Constructor() { | ||
@@ -79,8 +82,24 @@ if (this.preInitialize) { | ||
/** | ||
* @method | ||
* @see {@link extend-me.extend} | ||
* @desc Added to each returned extended class constructor. | ||
*/ | ||
Constructor.extend = extend; | ||
/** | ||
* @method | ||
* @param {string} [ancestorConstructorName] - If given, searches up the prototype chain for constructor with matching name. | ||
* @returns {function|null} Constructor of parent class; or ancestor class with matching name; or null | ||
*/ | ||
Constructor.parent = parentConstructor; | ||
var prototype = Constructor.prototype = Object.create(this.prototype); | ||
prototype.constructor = Constructor; | ||
extendedClassName = extendedClassName || prototype.$$CLASS_NAME || prototype.name; | ||
if (extendedClassName) { | ||
Object.defineProperty(Constructor, 'name', { value: extendedClassName, configurable: true }); | ||
prototype.$$CLASS_NAME = extendedClassName; | ||
@@ -178,2 +197,12 @@ } | ||
function parentConstructor(ancestorConstructorName) { | ||
var prototype = this.prototype; | ||
if (prototype) { | ||
do { | ||
prototype = Object.getPrototypeOf(prototype); | ||
} while (ancestorConstructorName && prototype && prototype.constructor.name !== ancestorConstructorName); | ||
} | ||
return prototype && prototype.constructor; | ||
} | ||
module.exports = extend; |
{ | ||
"name": "extend-me", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"main": "index.js", | ||
"description": "Yet another Backbone-like class extender", | ||
"description": "A class extender", | ||
"repository": { | ||
@@ -7,0 +7,0 @@ "type": "git", |
@@ -1,6 +0,9 @@ | ||
# extend-me | ||
Yet another Backbone-like class extender | ||
A class extender | ||
### Update history | ||
#### v2.5.0 | ||
* Added `parent(/*optional*/ancestorConstructorName)` to constructor to get the parent class's constructor or the named ancestor class's constructor. | ||
* Now resets returned constructor's `name` to `extendedClassName` OR `prototypeAdditions.$$CLASS_NAME` in the prototype OR `prototypeAdditions.name` | ||
#### v2.4.0 | ||
@@ -7,0 +10,0 @@ Previously, on instantiation, the `preInitialize` and `postInitialize` methods were called if and only if they were defined on the subclass's (extended object's) own prototype. This has been changed so that the "top" such methods on the prototype chain are now called, whether defined on the extended class or on an ancestor class. As before, these methods are called before and after the `initialize` cascade, respectively. Unlike `initialize`, however, there is no cascade; only the top most method is ever called. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15942
178
133