# subtypejs

> Minimalistic OOP library

Latest version **0.2.2** (published 2015-05-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install subtypejs
pnpm add subtypejs
yarn add subtypejs
bun add subtypejs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2015-05-10 |
| First published | 2014-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | dltcyganok |
| Maintainers | dtcyganok |
| Keywords | oop, inheritance, fast |

## Links

- npm: https://www.npmjs.com/package/subtypejs
- Repository: https://github.com/dtcyganok/subtype
- Issues: https://github.com/dtcyganok/subtype/issues
- npm.io page: https://npm.io/package/subtypejs

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2015-05-10
- 0.2.1 — 2014-11-16

## README

subtype
=======

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

##Install
For [bower](http://bower.io/) users:

    bower install subtype

For [node.js](http://nodejs.org/) users:

    npm install subtypejs

Also you can download [uncompressed](https://cdn.rawgit.com/dtcyganok/subtype/master/subtype.js) and [compressed](https://cdn.rawgit.com/dtcyganok/subtype/master/subtype.min.js) version from GitHub.

##Usage
In a **browser**:
```html
<script src="path/to/subtype.js"></script>
```

In an **AMD** loader:
```javascript
define(['subtype'], function (Subtype) {

  // code...

});
```

In **node.js**:
```javascript
var Subtype = require('subtypejs');

// code...
```

And then:
```javascript
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
```

---
_Source: https://npm.io/package/subtypejs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
