Socket
Socket
Sign inDemoInstall

extend-me

Package Overview
Dependencies
0
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    extend-me

Yet another Backbone-like class extender


Version published
Maintainers
1
Install size
10.2 kB
Created

Readme

Source

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

var Base = require('extend-me').Base;

var Parabola = Base.extend({
    initialize: function (a, b) {
        this.a = a;
        this.b = b;
    },
    calculate: function(x) {
        return this.a * Math.pow(x, 2) + (this.b * x);
    }
});

var ParabolaWithIntercept = Parabola.extend({
    initialize: function(a, b, c) {
        this.c = c;
    },
    calculate: function(x) {
        var y = Parabola.prototype.calculate.apply(this, arguments);
        return y + this.c;
    }
});

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

Constructors

The initialize methods at each level of inheritance are the constructors. 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 and inclucing the derived class in question.

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:

function Parabola() {
    this.initialize.apply(this, arguments);
}

To add initialization code to be executed before or after this chain of initialize calls, you an define methods preInitialize and postInitialize.

API documentation

Detailed API docs can be found here.

Regarding the git submodule jsdoc-template

See the note Regarding submodules for important information on cloning this repo or re-purposing its build template.

FAQs

Last updated on 20 Nov 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc