# parent.js

> Javascript inheritance for a 5 years old

Latest version **0.0.4** (published 2014-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install parent.js
pnpm add parent.js
yarn add parent.js
bun add parent.js
```

## 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.0.4 |
| Published | 2014-10-24 |
| First published | 2014-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jose Vidal |
| Maintainers | javidgon |
| Keywords | inheritance, wrapper, humans |

## Links

- npm: https://www.npmjs.com/package/parent.js
- Repository: https://github.com/javidgon/parent.js
- Issues: https://github.com/javidgon/parent.js/issues
- npm.io page: https://npm.io/package/parent.js

## Recent versions

- 0.0.4 (latest) — 2014-10-24
- 0.0.3 — 2014-10-23

## README

parent.js
=========
[![Build Status](https://travis-ci.org/javidgon/parent.js.svg)](https://travis-ci.org/javidgon/parent.js)
> Javascript inheritance for a 5 years old

**Javascript** is great, we all know that. **Prototypal inheritance** is really powerful and some people can do awesome
things with that, but let's face it, it has its quirks. Also 99% of the time we only want to create `Classes` and do simple inheritance. It shouldn't be complicated or prone to errors.

**Parent.js** is a micro library (less than 30 lines of code), that allows you to create javascript `Classes` (or in `js` terminology `function constructors`) and, at the same time, inherit easily from other Classes.

## Use

For using this library, you just need to create your `Classes` with the following syntax:
```javascript
var Person = Class({
  // Methods go here...
  ...
}, <BaseClass>)
```

And this is it! Please keep in mind that `<BaseClass>` is optional. Not every class needs to inherit! :smirk:.
Let's see more examples:

```javascript
var Person = Class({
  initialize: function (name, surname) {
    this.name = name;
    this.surname = surname;
  },
  sayHi: function () {
    return 'Hi I\'m a Person!!';
  }
});

var Student = Class({
  initialize: function (name, surname, bachelor) {
    this.super.initialize(name, surname);
    this.bachelor = bachelor;
  },
  study: function () {
    return 'I\'m Studying!'
    
  },
  sayHi: function () {
    return 'Hi I\'m a Student!!';
  }
}, Person);

var student = new Student('Jose', 'Vidal', 'Computer Science');

console.dir(student.name, student.bachelor);
// Output: "Jose, Computer Science" 

console.dir(student.sayHi());
// Output: "Hi I'm a Student!" 

console.dir(student.super.sayHi());
// Output: "Hi I'm a Person!" 

console.log(s1 instanceof Student);
// Output: true 
console.log(s1 instanceof Person);
// Output: true 
```
You can see how the use of `parent's methods` is trivial with the attribute `super` from the instances.

## Advanced Use
A nice feature is the possibility of creating `class` methods by prepending `__` (two underscores) to the name of the method.

```javascript
var Person = Class({
  initialize: function (name, surname) {
    this.name = name;
    this.surname = surname;
  },
  __thisIsAClassMethod: function () {
    return 'Hi I\'m a classmethod!';
  },
  thisIsAnInstanceMethod: function () {
    return 'Hi I\'m an instancemethod!';
  }
});

var person = new Person('Jose', 'Vidal');

// Class:
console.log(Person.thisIsAClassMethod());
// Output: 'Hi I\'m a classmethod!'

console.log(Person.thisIsAnInstanceMethod());
// Output: TypeError: undefined is not a function

// Instance:
console.log(person.thisIsAClassMethod());
// Output: TypeError: undefined is not a function

console.log(person.thisIsAnInstanceMethod());
// Output: 'Hi I\'m an instancemethod!'
```

## Installation

```javascript
bower install parent.js
```
or
```javascript
npm install parent.js
```

**Enjoy!**

## Contribute

Simply make a PR.

## Licente

MIT

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