Type (typejs)
A Type creation system using a lightweight prototypal inheritance implementation based on backbone.js.
Quick Start
JAM
jam install typejs
var type = require('typejs');
AMD
-
git clone https://github.com/pieter-vanderwerff/type
orgit submodule add https://github.com/pieter-vanderwerff/type
-
Configure your loader with a package:
packages:name: 'typejs' location: 'path/to/type/' main: 'type'// ... other packages ... -
define(['typejs', ...], function(type, ...) { ... });
orrequire(['typejs', ...], function(type, ...) { ... });
Script Tag
git clone https://github.com/pieter-vanderwerff/type
orgit submodule add https://github.com/pieter-vanderwerff/type
<script src="path/to/type/type.js"></script>
type
will be available aswindow.typejs
Node
npm install typejs
var type = require('typejs');
API
type()
Create a type object:
var Foo = ; // Returns a newable objectvar foo1 = ;var foo2 = ;
constructor / initialize function
As with backbone.js if the object has a function called initialize it will be run on the creation of an instance, receiving any arguments passed to the type.
var Foo = ; // Create instances passing options to the initialize functionvar foo1 = bar: 10 ;var foo2 = bar: 17 ;
type().extend()
Extend a type object:
var Foo = ; // Extend Foovar Foostream = Foo; // Create instances of both typesvar foo1 = ;var foo2 = ;
Running the Unit Tests
Install buster.js
npm install -g buster
Run unit tests in Node:
buster test -e node
Run unit tests in Browsers (and Node):
buster server
- this will print a url- Point browsers at /capture, e.g.
localhost:1111/capture
buster test
orbuster test -e browser