# viral

> As simple as JS OO can be; in a tiny package

Latest version **0.0.4** (published 2013-04-17) · BSD license · 0 weekly downloads

## Install

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

## 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 | 2013-04-17 |
| First published | 2013-04-12 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | hughfdjackson |
| Maintainers | hughfdjackson |
| Keywords | oo, prototypal, prototype |

## Links

- npm: https://www.npmjs.com/package/viral
- Repository: https://github.com/hughfdjackson/viral
- npm.io page: https://npm.io/package/viral

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.0.4 (latest) — 2013-04-17
- 0.0.3 — 2013-04-13
- 0.0.2 — 2013-04-13
- 0.0.1 — 2013-04-12

## README

# Viral

Viral is a tiny, pure prototypal OO library for javascript; taking the best parts of [boo](https://github.com/killdream/boo).

[![browser support](https://ci.testling.com/hughfdjackson/viral.png)](https://ci.testling.com/hughfdjackson/viral)

## Why

The most consistent, easiest way to OO in javascript is pure prototypally - and Viral makes this a snap (and packs a tiny punch in the process - < 0.5kb minified).

## API

Viral is a simple base object with two methods:

### .extend

.extend creates an object that inherits from the object on which it's called, and copies any
properties passed to .extend into that new object:

```javascript
var Person = Viral.extend({
	init: function(firstName, lastName){
		this.firstName = firstName
		this.lastName = lastName
	},
	fullName: function(){ return this.firstName + this.lastName }
})

// extend is inherited by Person, so we can extend further:
var Coder = Person.extend({
	likesCode: true
})
```

Because Viral uses pure prototypal inheritance - objects inheriting directly from objects - Coder and Person are just objects like any other:

```javascript
console.log(Person)

//  {
//  	init: [Function],
//  	fullName: [Function]
//  }

console.log(Coder)

//  {
//  	init: [Function],
//  	fullName: [Function],
//  	likesCode: true
//  }
```

### .make

.make creates an object that inherits from the object on which it's called, and calls the init method
of this new object with any arguments you pass in.


```javascript
// using Coder from the above example:
var hugh = Coder.make('hugh', 'jackson')

hugh.fullName() //= 'hugh jackson'
hugh.likesCode  //= true
```

## Install

### node

`npm install viral`, then require:

```javascript
var Viral = require('viral')

// use `Viral` here
```

### browser

include as a script tag:

```html
<!doctype html>
<html>
	<head></head>
	<body>
		<script src="libs/viral.min.js"></script>
		<script>
		// use `Viral` here
		</script>
	</body>
</html>
```

### requirejs

include as a script.  e.g., from the libs/ folder:

```javascript
require(['libs/viral.min'], function(Viral){
	// use `Viral` here
})
```

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