uptown
Simple ways to extend prototypes
Last updated 10 years ago by smizell .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install uptown 
SYNC missed versions from official npm registry.

Uptown

Build Status

Simplify prototypical inheritance. This tries to provide some simple constructs for providing functionality you get with ES6 classes, such as:

  • Constructor functions
  • Static class methods
  • Getter and setter methods

Install

Using npm:

npm install uptown --save

Using cdn:

<script src="https://unpkg.com/uptown/dist/uptown.min.js"></script>
  • dist/uptown.js contains uptown and requires lodash to be loaded separately. Can be used with requirejs.
  • dist/uptown.min.js contains minified uptown and dependencies (lodash).

Usage

Use extendify to add the extend method to a class (note: it mutates the original class).

The extend class method takes three options arguments:

  1. Object of instance properties
  2. Object of static methods and properties
  3. Object of getter and setter mutators
var extendify = require('uptown').extendify;

var Original = function() {};

Original.prototype.hello = function(value) {
  return 'Hello, ' + value;
}

extendify(Original);

var SubClass = Original.extend({
  // Specify a constructor for the new class
  constructor: function() {
    // Call parent constructor
    Original.apply(this, arguments);
  },

  hello: function(value) {
    // Add exclamation point
    return Original.prototype.hello.call(this, value + '!')
  }
}, {
  // Specify static methods and properties
  staticMethod: function() {}
}, {
  // Specify getters and setters for the new class
  foo: {
    get: function() {},
    set: function() {}
  }
});

New classes may also be created using the createClass function. The createClass function works just like .extend.

var createClass = require('uptown').createClass;

var Foo = createClass({
  constructor: function() {
    this.foo = 'bar';
  }
});

Current Tags

  • 1.1.0                                ...           latest (6 years ago)

9 Versions

  • 1.1.0                                ...           6 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
  • 0.4.1                                ...           8 years ago
  • 0.4.0                                ...           10 years ago
  • 0.3.0                                ...           10 years ago
  • 0.2.0                                ...           10 years ago
  • 0.1.1                                ...           10 years ago
  • 0.1.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 1
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE