Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extend-me

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extend-me - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

103

index.js

@@ -7,3 +7,3 @@ 'use strict';

*
* @returns {extendedConstructor} A new constructor, extended from the given context, possibly with some prototype additions.
* @returns {ChildConstructor} A new constructor, extended from the given context, possibly with some prototype additions.
*

@@ -16,29 +16,42 @@ * @desc Extends "objects" (constructors), with optional additional code, optional prototype additions, and optional prototype member aliases.

*
* For example, if you wish to extend `BaseConstructor` to a new constructor with prototype overrides and/or additions, usage is:
* For example, if you wish to be able to extend `BaseConstructor` to a new constructor with prototype overrides and/or additions, basic usage is:
*
* ```javascript
* extend.call(BaseConstructor, prototypeAdditions);`
* var Base = require('extend-me').Base;
* var BaseConstructor = Base.extend(basePrototype); // mixes in .extend
* var ChildConstructor = BaseConstructor.extend(childPrototypeOverridesAndAdditions);
* var GrandchildConstructor = ChildConstructor.extend(grandchildPrototypeOverridesAndAdditions);
* ```
*
* More elegantly, you can mix it in:
* This function (`extend()`) is added to the new extended object constructor as a property `.extend`, essentially making the object constructor itself easily "extendable." (Note: This is a property of each constructor and not a method of its prototype!)
*
* ```javascript
* BaseConstructor.extend = extend
* ```
* @param {string} [extendedClassName] - This is simply added to the prototype as $$CLASS_NAME. Useful for debugging because all derived constructors appear to have the same name ("Constructor") in the debugger. This property is ignored when `extend.extendedClassNames` is set to `false`.
*
* and call it like this:
* @param {extendedPrototypeAdditionsObject} [prototypeAdditions] - Object with members to copy to new constructor's prototype. Most members will be copied to the prototype. Some members, however, have special meanings as explained in the {@link extendedPrototypeAdditionsObject|type definition} (and may or may not be copied to the prototype).
*
* ```javascript
* var ExtendedConstructor = BaseConstructor.extend(prototypeAdditions);
* ```
*
* This function (`extend()`) is added to the new extended object constructor as a property `.extend`, essentially making the object constructor itself easily "extendable." (Note: This is a property of each constructor and not a method of its prototype!)
*
* @param {extendedPrototypeAdditionsObject} prototypeAdditions - Object with members to copy to new constructor's prototype. Most members will be copied to the prototype. Some members, however, have special meanings as explained in the {@link extendedPrototypeAdditionsObject|type definition} (and may or may not be copied to the prototype).
*
* @memberOf extend-me
*/
function extend(prototypeAdditions) {
function extend(extendedClassName, prototypeAdditions) {
switch (arguments.length) {
case 0:
prototypeAdditions = {};
break;
case 1:
prototypeAdditions = extendedClassName;
if (typeof prototypeAdditions !== 'object') {
throw 'Single parameter overload must be object.';
}
extendedClassName = undefined;
break;
case 2:
if (typeof extendedClassName !== 'string' || typeof prototypeAdditions !== 'object') {
throw 'Two parameter overload must be string, object.';
}
break;
default:
throw 'Too many parameters';
}
function Constructor() {
if (prototypeAdditions && prototypeAdditions.preInitialize) {
if (prototypeAdditions.preInitialize) {
prototypeAdditions.preInitialize.apply(this, arguments);

@@ -49,3 +62,3 @@ }

if (prototypeAdditions && prototypeAdditions.postInitialize) {
if (prototypeAdditions.postInitialize) {
prototypeAdditions.postInitialize.apply(this, arguments);

@@ -60,29 +73,26 @@ }

if (prototypeAdditions) {
for (var key in prototypeAdditions) {
if (prototypeAdditions.hasOwnProperty(key)) {
var value = prototypeAdditions[key];
switch (key) {
case 'initializeOwn':
// already called above; not needed in prototype
break;
case 'aliases':
for (var alias in value) {
if (value.hasOwnProperty(alias)) {
makeAlias(value[alias], alias);
}
if (extend.extendedClassNames) {
prototype.$$CLASS_NAME = extendedClassName;
}
for (var key in prototypeAdditions) {
if (prototypeAdditions.hasOwnProperty(key)) {
var value = prototypeAdditions[key];
switch (key) {
case 'initializeOwn':
// already called above; not needed in prototype
break;
case 'aliases':
for (var alias in value) {
if (value.hasOwnProperty(alias)) {
makeAlias(value[alias], alias);
}
break;
case '$$CLASS_NAME':
if (extend.copyClassNames) {
prototype[key] = value;
}
break;
default:
if (typeof value === 'string' && value[0] === '#') {
makeAlias(value, key.substr(1));
} else {
prototype[key] = value;
}
}
}
break;
default:
if (typeof value === 'string' && value[0] === '#') {
makeAlias(value, key.substr(1));
} else {
prototype[key] = value;
}
}

@@ -98,3 +108,3 @@ }

}
extend.copyClassNames = true;
extend.extendedClassName = true;

@@ -115,3 +125,2 @@ extend.Base = function () {};

* @property {*} [arbitraryProperties] - Any additional arbitrary properties defined here will be added to the new constructor's prototype. (Use arbitrary identifiers here; don't use the name `aribitraryProperties`!)
* @property {string} [$$CLASS_NAME] - This is simply copied to the prototype. Useful for debugging purposes because all derived constructors appear to have the same name ("Constructor") in the debugger. This property is ignored when `extend.classnames` is set to `false`.
*/

@@ -118,0 +127,0 @@

{
"name": "extend-me",
"version": "2.0.0",
"version": "2.1.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "description": "Yet another Backbone-like class extender",

# extend-me
Yet another Backbone-like class extender
**Version 2.0 has a breaking changes:**
1. `this.super` has been removed as it suffered the "grandchild" problem; use `YourBaseClass.prototype` instead.
2. The `.initializeOwn` method has been renamed to `.postInitialize`.
## Synopsis

@@ -42,3 +38,4 @@

classes that implement it, starting with the most distant ancestor all the way to
and inclucing the derived class in question.
and including the derived class in question. Each `initialize` method is called
with the same parameters passed to the constructor.

@@ -45,0 +42,0 @@ If you intend to instantiate the base class (`Parabola` in the above) directly

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc