Viral
Viral is a tiny, pure prototypal OO library for javascript; taking the best parts of boo.
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:
var Person = Viral // extend is inherited by Person, so we can extend further:var Coder = Person
Because Viral uses pure prototypal inheritance - objects inheriting directly from objects - Coder and Person are just objects like any other:
console // {// init: [Function],// fullName: [Function]// } console // {// 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.
// using Coder from the above example:var hugh = Coder hugh //= 'hugh jackson'hughlikesCode //= true
Install
node
npm install viral
, then require:
var Viral = // use `Viral` here
browser
include as a script tag:
requirejs
include as a script. e.g., from the libs/ folder: