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 2.7.0 to 2.7.1

33

index.js

@@ -5,33 +5,30 @@ 'use strict';

/** @summary Extends an existing constructor into a new constructor.
/** @summary Extends an existing "class" (constructor function) into a new "subclass.
*
* @returns {Constructor} A new constructor, extended from the given context, possibly with some prototype additions.
* @returns {function} A new class (constructor function), extended from the class provided in the execution context, possibly with some prototype additions.
*
* @desc Extends "objects" (constructors), with optional additional code, optional prototype additions, and optional prototype member aliases.
* @desc Extends a class creating a subclass with optional prototype additions.
*
* > CAVEAT: Not to be confused with Underscore-style .extend() which is something else entirely. I've used the name "extend" here because other packages (like Backbone.js) use it this way. You are free to call it whatever you want when you "require" it, such as `var inherits = require('extend')`.
*
* Provide a constructor as the context and any prototype additions you require in the first argument.
* Provide any prototype additions you require in the first argument, including optional constructor code in a method called `initialize`.
*
* For example, if you wish to be able to extend `BaseConstructor` to a new constructor with prototype overrides and/or additions, basic usage is:
* For example, if you wish to be able to extend your class `MyBase` to a new "class" (i.e., constructor function) with prototype overrides and/or additions, basic usage is:
*
* ```javascript
* var Base = require('extend-me').Base;
* var BaseConstructor = Base.extend(basePrototype); // mixes in .extend
* var ChildConstructor = BaseConstructor.extend(childPrototypeOverridesAndAdditions);
* var GrandchildConstructor = ChildConstructor.extend(grandchildPrototypeOverridesAndAdditions);
* function MyBase() { ... }
* MyBase.prototype = { ... };
* MyBase.extend = extend; // mix in .extend
* var MyChild = MyBase.extend(childPrototypeOverridesAndAdditions);
* var MyGrandchild = MyChild.extend(grandchildPrototypeOverridesAndAdditions);
* ```
*
* 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!)
* This `extend` function is automatically added to the new extended class (constructor function) as a static property so it will itself be "extendable."
*
* @this Base class being extended from (i.e., its constructor function object).
* @this Function - The base class (constructor function) being extended from.
*
* @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.
* @param {string} [extendedClassName=prototypeAdditions.$$CLASS_NAME || prototypeAdditions.name] - If defined, added to the constructor as static `name` property; and to the prototype as `$$CLASS_NAME`. Useful for debugging because all derived constructors appear to have the same name (`Constructor`) in the debugger. (If omitted, 2nd parameter is promoted to first position.)
*
* @param {extendedPrototypeAdditionsObject} [prototypeAdditions] - Object with members to copy to new constructor's prototype.
* @param {prototypeAdditionsObject} [prototypeAdditions] - Object with members to define in the new constructor's prototype.
*
* @property {boolean} [debug] - See parameter `extendedClassName` _(above)_.
*
* @property {object} Base - A convenient base class from which all other classes can be extended.
*
* @memberOf extend-me

@@ -191,3 +188,3 @@ */

/** @typedef {object} extendedPrototypeAdditionsObject
/** @typedef {object} prototypeAdditionsObject
* @desc All members are copied to the new object. The following have special meaning.

@@ -194,0 +191,0 @@ * @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.

{
"name": "extend-me",
"version": "2.7.0",
"version": "2.7.1",
"main": "index.js",

@@ -8,26 +8,13 @@ "description": "A class extender",

"type": "git",
"url": "https://github.com/joneit/extend-me"
"url": "https://github.com/fin-hypergrid/extend-me"
},
"scripts": {
"test": "gulp test"
"build": "sh build.sh",
"test": "open build/demo.html"
},
"author": "Jonathan Eiten",
"license": "MIT",
"devDependencies": {
"browser-sync": "^2.10.0",
"gulp": "^3.9.0",
"gulp-browserify": "^0.5.1",
"gulp-eslint": "^1.1.0",
"gulp-exclude-gitignore": "^1.0.0",
"gulp-load-plugins": "^1.1.0",
"gulp-mirror": "^0.4.0",
"gulp-mocha": "^2.2.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-uglify": "^1.5.1",
"gulp-util": "^3.0.7",
"multipipe": "^0.2.1",
"run-sequence": "^1.1.4",
"should": "^7.1.1"
"dependencies": {
"uglify-js": "^3.8.0"
}
}

@@ -5,2 +5,4 @@ # extend-me

> Update: This module is essentially obsoleted by ES6 [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class) syntax, which is recommended going forward when possible (when your target browsers support it or your code is transpiled for unsupported browsers).
## Require/include

@@ -10,2 +12,6 @@

```bash
npm install --save extend-me
```
```javascript

@@ -18,9 +24,11 @@ var extend = require('extend-me');

```html
<script src="http://joneit.github.io/extend-me/extend-me.js"></script>
<script src="http://fin-hypergrid.github.io/extend-me/extend-me.js"></script>
```
or:
```html
<script src="http://joneit.github.io/extend-me/extend-me.min.js"></script>
<script src="http://fin-hypergrid.github.io/extend-me/extend-me.min.js"></script>
```
> Do not confuse this `extend` function with Underscore-style .extend() which is something else entirely. I've used the name "extend" here because other packages (like Backbone.js) use it this way. You are free to call it whatever you want when you "require" it, such as `var inherits = require('extend')`.
## Syntax

@@ -112,11 +120,11 @@

In the example above, on instantiation (`var paraboloa = new ParabolaWithIntercept(3, 2, 1)`),
In the example above, on instantiation (`var parabola = new ParabolaWithIntercept(3, 2, 1)`),
`Parabola.prototype.initialize` is called first; then `ParabolaWithIntercept.prototype.initialize`.
To add initialization code to be executed _before_ and/or _after_ this chain of `initialize`
calls, you an define methods `preInitialize` and/or `postInitialize`, respectively. These are _not_
calls, you can define methods `preInitialize` and/or `postInitialize`, respectively. These are _not_
part of the initialization chain. They are only called on the object being instantiated;
they are not called when a derived class is being instantiated.
For example, in the sample usage above, if `MyClass` had had a `preInitialize` method,
it would be called on `a`'s intantiation but not `b`'s.
it would be called on `a`'s instantiation but not `b`'s.

@@ -132,2 +140,3 @@ ## `Base`

MyBase.extend = extend;
```

@@ -139,2 +148,4 @@ The following methods are available in the prototype of `extend.Base`.

> NOTE: `super` is not a reference to ancestral constructor; ancestral constructors are always called automatically, as described above.
### `superMember(memberName)`

@@ -149,12 +160,20 @@ Find member on prototype chain beginning with super class.

## API documentation
Detailed API docs can be found [here](http://joneit.github.io/extend-me/extend-me.html).
## Demo
A demo can be found [here](http://joneit.github.io/extend-me/demo.html).
A demo/test using the `ParabolaWithIntercept` class described above can be found on [github.io](http://fin-hypergrid.github.io/extend-me).
## Update history
### v2.7.1
* Simplified repo as it no longer has any dependencies (since 2.7.0)
* Removed gulpfile.js and its dependencies
* Added build.sh
* Removed vapid test
* Removed custom jsdoc template
* Moved to new home in the fin-hypergrid Github organization
### v2.7.0
* Added `getClassName` as both static method to extended class and as prototype method to `Base`.
* Removed `overrider` dependency.
### v2.6.0

@@ -174,6 +193,1 @@ * Added `postExtend`, an optional static method of the base "class" (constructor). When defined, it is called at the end of `extend()` with the new "class" (new constructor) as its sole parameter. This permits miscellaneous tweaking and cleanup of the new class.

## Submodules
See the note [Regarding submodules](https://github.com/openfin/rectangular#regarding-submodules)
for important information on cloning this repo or re-purposing its build template.
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