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


viral is a tiny, pure prototypal OO library for javascript; taking the best parts of boo.

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).

viral exposes a base object to inherit from - viral.Base. It has two methods:

viral.Base.extend creates an object that inherits from viral.Base, and copies any properties passed to .extend into that new object:

var viral = require('viral')
var Person = viral.Base.extend({
        this.firstName = firstName
        this.lastName = lastName
    fullNamefunction(){ return this.firstName + this.lastName }

viral.base.make creates an object that inherits from viral.Base, and calls the init method of this new object with any arguments you pass in.

// continuing with the Person example from `viral.Base.extend` 
var hugh = Person.make('hugh', 'jackson')   // Person inherits .make from viral.Base 
hugh.fullName() //= 'hugh jackson' 

npm install viral, then require:

var viral = require('viral')
// use `viral` here 

include as a script tag:

<doctype html>
        <script src="libs/viral.js"></script> 
        // use `viral` here 

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

require(['libs/viral'], function(viral){
    // use `viral` here