simpler-extend
Simple 'extend' helper for inheritance and subclassing
Last updated 6 years ago by rstacruz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install simpler-extend 
SYNC missed versions from official npm registry.

simpler-extend

Simple 'extend' helper for inheritance and subclassing. Adapted from Backbone.js's Model.extend and CoffeeScript. This works like simple-extend, except this does not have any dependencies.

Status


Usage

Assign it to your base class's .extend:

function Shape() { ... }
Shape.extend = require('simpler-extend');

Then use it to subclass:

var Circle = Shape.extend({
  getArea: function () {
    return this.width * this.height;
  }
});

You can also add a constructor as constructor:

var Circle = Shape.extend({
  constructor: function () { ... }
});

Calling methods from the base class:

var Circle = Shape.extend({
  getArea: function () {
    var super = Shape.prototype.getArea.apply(this, arguments);
    return super * Math.PI;
  }
});

See Backbone.js's Model.extend documentation for more details.


Thanks

simpler-extend © 2015+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Current Tags

  • 1.1.0                                ...           latest (6 years ago)

4 Versions

  • 1.1.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |