0.0.6 • Published 8 years ago

extensive v0.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

extensive Build Status Coverage Status

Tiny javascript library for extending objects Backbone-style.

Installation

npm install extensive

Usage

const extend = require('extensive');

const Animal = extend(function(name) {
    this.name = name;
}, {
    speak: function() {
        console.log("...");
    }
}, {
    isAnimal: function(obj) {
        return obj instanceOf Animal;
    }
});

var test = new Animal("test");

test.speak();
// "...""

A constructor created with extensive will provide a static extend method to create subclasses.

const Cat = Animal.extend(function(name, owner) {
    this.name = name;
    this.owner = owner;
}, {
    speak: function() {
        console.log("meowww");
    },

    showAffection: function(person) {
        if (person === this.owner) {
            console.log("purr");
        } else {
            console.log("hissss");
        }
    }
});

var felix = new Cat("felix", "brebory");

felix.speak();
// "meowww"

felix.showAffection("gina");
// "hissss"

felix.showAffection("brebory");
// "purr"

Cat.isAnimal(felix);
// true
0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago