Socket
Socket
Sign inDemoInstall

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 1.0.0 to 1.0.1

38

index.js
'use strict';
var _ = require('object-iterators');
/** @namespace extend **/
/** @summary Extends an existing constructor into a new constructor.
*
* @returns {function} A new constructor, extended from the given context, possibly iwth some prototype additions.
* @returns {extendedConstructor} A new constructor, extended from the given context, possibly with some prototype additions.
*

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

*
* @param {object} prototype - Object with members to copy to new constructor's prototype. Some have special meanings:
* * `initialize: function() {...}` - Additional constructor code for new object. Gets passed new object as context + same args as constructor itself. Called on instantiation after similar function in all ancestors called with same signature.
* * `initializeOwn: function() {...}` - Additional constructor code for new object. Gets passed new object as context + same args as constructor itself. Called on instantiation after (all) the `initialize` function(s).
* * `extendable: true` - Adds this function (`extend()`) as a property `.extend()` of the new extended object constructor, essentially making the object constructor itself easily "extensible" (i.e, able to create new constructors that inherit form this constructor). (Alternatively, even without doing this, you can always extend from any constructor by calling `extend.call(ConstructorToInheritFrom, {...})`.) (Not added to prototype.)
* * `aliases: {...}` - Hash of aliases for prototype members in form `{ key: 'member', ... }` where `key` is the name of an alieas and `'member'` is the name of an existing member in the prototype. Each such key is added to the prototype as a reference to the named member. (The `aliases` object itself is *not* added to prototype.) Alternatively:
* * `key: '#xxx'` - Adds an alias `key` with same value as existing member `xxx`. Simpler though subtler.
* @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
*/

@@ -52,3 +49,3 @@ function extend(prototypeAdditions) {

if (prototypeAdditions) {
_(prototypeAdditions).each(function (value, key) {
for (var key in prototypeAdditions) {
switch (key) {

@@ -62,5 +59,8 @@ case 'initializeOwn':

case 'aliases':
_(prototypeAdditions.aliases).each(makeAlias);
for (var alias in prototypeAdditions.aliases) {
makeAlias(prototypeAdditions.aliases[alias]);
}
break;
default:
var value = prototypeAdditions[key];
if (typeof value === 'string' && value[0] === '#') {

@@ -72,3 +72,3 @@ makeAlias(value, key.substr(1));

}
});
}
}

@@ -78,3 +78,3 @@

function makeAlias(value, key) {
function makeAlias(value, key) { // eslint-disable-line no-shadow
prototype[key] = prototypeAdditions[value];

@@ -84,2 +84,16 @@ }

/** @typedef {function} extendedConstructor
* @property prototype.super - A reference to the prototype this constructor was extended from.
* @property [extend] - If `prototypeAdditions.extendable` was truthy, this will be a reference to {@link extend.extend|extend}.
*/
/** @typedef {object} extendedPrototypeAdditionsObject
* @property {function} [initialize] - Additional constructor code for new object. This method is added to the new constructor's prototype. Gets passed new object as context + same args as constructor itself. Called on instantiation after similar function in all ancestors called with same signature.
* @property {function} [initializeOwn] - Additional constructor code for new object. This method is added to the new constructor's prototype. Gets passed new object as context + same args as constructor itself. Called on instantiation after (all) the `initialize` function(s).
* @property {boolean} [extendable] - Truthy value adds this function (`extend()`) as a property `.extend()` of the new extended object constructor, essentially making the object constructor itself easily "extensible" (i.e, able to create new constructors that inherit form this constructor). (Alternatively, even without doing this, you can always extend from any constructor by calling `extend.call(ConstructorToInheritFrom, {...})`.) (Not added to prototype.)
* @property {object} [aliases] - Hash of aliases for prototype members in form `{ key: 'member', ... }` where `key` is the name of an alieas and `'member'` is the name of an existing member in the prototype. Each such key is added to the prototype as a reference to the named member. (The `aliases` object itself is *not* added to prototype.) Alternatively:
* @property {string} [keys] - Arbitrary property names defined here with string values starting with a `#` character will alias the actual properties named in the strings (following the `#`). This is an alternative to providing an `aliases` hash, perhaps simpler (though subtler). (Use arbitrary identifiers here; don't use the name `keys`!)
* @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`!)
*/
/** @summary Call all `initialize` methods found in prototype chain.

@@ -86,0 +100,0 @@ * @desc This recursive routine is called by the constructor.

{
"name": "extend-me",
"version": "1.0.0",
"version": "1.0.1",
"main": "index.js",

@@ -26,6 +26,3 @@ "description": "Yet another Backbone-like class extender",

"should": "^7.1.1"
},
"dependencies": {
"object-iterators": "^1.0.0"
}
}
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