New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

subtypejs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subtypejs

Minimalistic OOP library

latest
Source
npmnpm
Version
0.2.2
Version published
Maintainers
1
Created
Source

subtype

Simple OOP library. Works fast like native inheritance (see benchmarks). The library does not contain any super or analogs because it contaminates the prototype and a bad influence on performance.

##Install For bower users:

bower install subtype

For node.js users:

npm install subtypejs

Also you can download uncompressed and compressed version from GitHub.

##Usage In a browser:

<script src="path/to/subtype.js"></script>

In an AMD loader:

define(['subtype'], function (Subtype) {

  // code...

});

In node.js:

var Subtype = require('subtypejs');

// code...

And then:

var Human = Subtype.extend({
  constructor: function (name) {
    this.name = name;
  },
  say: function (words) {
    return this.name + ': ' + words;
  }
});

var Actor = Human.extend({
  say: function (words) {
    // explicit call the super method
    return 'actor ' + Human.prototype.say.call(this, words);
  }
});

var human = new Human('Robert');
console.log(human.say('Hi!')); // => "Robert: Hi!"

var actor = new Actor('Jeremy');
console.log(actor.say('Hello!')); // => "actor Jeremy: Hello!"

console.log(
  human instanceof Human &&
  human instanceof Subtype &&
  actor instanceof Actor &&
  actor instanceof Human &&
  actor instanceof Subtype
); // => true

console.log(
  Subtype === Subtype.prototype.constructor &&
  Human === Human.prototype.constructor &&
  Actor === Actor.prototype.constructor
); // => true

Keywords

oop

FAQs

Package last updated on 10 May 2015

Did you know?

Socket

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