0.0.4 • Published 11 years ago

viral v0.0.4

Weekly downloads
6
License
-
Repository
github
Last release
11 years ago

viral

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

browser support

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

API

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

viral.Base.extend

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({
	init: function(firstName, lastName){
		this.firstName = firstName
		this.lastName = lastName
	},
	fullName: function(){ return this.firstName + this.lastName }
})

viral.Base.make

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'

Install

node

npm install viral, then require:

var viral = require('viral')

// use `viral` here

browser

include as a script tag:

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

requirejs

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

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

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago