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.2.1 to 2.2.2

11

index.js

@@ -109,4 +109,11 @@ 'use strict';

extend.Base = function () {};
extend.Base.extend = extend;
function Base() {}
Base.prototype = {
constructor: Base.prototype.constructor,
get super() {
return Object.getPrototypeOf(Object.getPrototypeOf(this));
}
};
Base.extend = extend;
extend.Base = Base;

@@ -113,0 +120,0 @@ /** @typedef {function} extendedConstructor

2

package.json
{
"name": "extend-me",
"version": "2.2.1",
"version": "2.2.2",
"main": "index.js",

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

@@ -6,3 +6,3 @@ # extend-me

Node.js:
Node.js / Browserify:

@@ -13,5 +13,8 @@ ```javascript

Browser:
Browsers:
_The client can download directly from the GitHub CDN with one or the other of the following `<script>` tags:
```html
<script src="http://joneit.github.io/extend-me/extend-me.js"></script>
<script src="http://joneit.github.io/extend-me/extend-me.min.js"></script>

@@ -30,6 +33,10 @@ ```

var MyChildClass = MyClass.extend({
initialize: function () { /* called after base class's initialize() */ },
preInitialize: function () { ... }, // called before base class's initialize() */
initialize: function () { ... }, // called after base class's initialize() and before derived class's initialize() */
postInitialize: function () { ... }, // called after this class's initialize() */
member1: ..., // overrides base class's definition of member1
member3: ...
};
var a = new MyClass(), b = new MyChildClass();
```

@@ -55,3 +62,3 @@

calculate: function(x) {
var y = Parabola.prototype.calculate.apply(this, arguments);
var y = this.super.calculate.apply(this, arguments);
return y + this.c;

@@ -62,3 +69,3 @@ }

var parabola = new ParabolaWithIntercept(3, 2, 1),
y = ParabolaWithIntercept(-3); // yields 22
y = parabola.calculate(-3); // yields 22
```

@@ -68,20 +75,29 @@

The `initialize` methods at each level of inheritance are the constructors.
You may optionally supply an `initialize` method to be called as your constructor.
It will be called on object instantiation with the same parameters as passed to the actual constructor.
## Initialization Chain
There may be `initialize` methods at each level of inheritance.
Instantiating a derived class will automatically call `initialize` on all ancestor
classes that implement it, starting with the most distant ancestor all the way to
classes that implement it, starting with the most distant ancestor all the way up to
and including the derived class in question. Each `initialize` method is called
with the same parameters passed to the constructor.
with the same parameters as passed to the constructor.
If you intend to instantiate the base class (`Parabola` in the above) directly
(_i.e.,_ it is not "abstract"), include the following in the constructor:
In the example above, on instantiation (`var paraboloa = new ParabolaWithIntercept(3, 2, 1)`),
`Parabola.prototype.initialize` is called first; then `ParabolaWithIntercept.prototype.initialize`.
```javascript
function Parabola() {
this.initialize.apply(this, arguments);
}
```
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_
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.
To add initialization code to be executed before or after this chain of `initialize`
calls, you an define methods `preInitialize` and `postInitialize`.
## Super
You can reference the immediate ancestor in the prototype chain with the `super`
(a getter on `Base`'s prototype), as shown in the example above.
### API documentation

@@ -95,9 +111,2 @@

### CDN versions
To use in a browser, you have two options:
1. Incorporate the node module into your own browserified project.
2. Use the browserified versions [`extend-me.js`](http://joneit.github.io/extend-me/extend-me.js) or [`extend-me.min.js`](http://joneit.github.io/extend-me/extend-me.min.js) available on the Github pages CDN.
### Submodules

@@ -104,0 +113,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