0.1.0 • Published 13 years ago
typejs v0.1.0
#Type (typejs)
A Type creation system using a lightweight prototypal inheritance implementation based on backbone.js.
Quick Start
JAM
jam install typejsvar type = require('typejs');
AMD
git clone https://github.com/pieter-vanderwerff/typeorgit submodule add https://github.com/pieter-vanderwerff/typeConfigure 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/typeorgit submodule add https://github.com/pieter-vanderwerff/type<script src="path/to/type/type.js"></script>typewill be available aswindow.typejs
Node
npm install typejsvar type = require('typejs');
API
type()
Create a type object:
var Foo = type( { foo: 'bar' } );
// Returns a newable object
var foo1 = new Foo();
var foo2 = new Foo();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 = type( {
initialize: function( options ) {
this._bar = options.bar;
}
} );
// Create instances passing options to the initialize function
var foo1 = new Foo( { bar: 10 } );
var foo2 = new Foo( { bar: 17 } );type().extend()
Extend a type object:
var Foo = type( { foo: 10 } );
// Extend Foo
var Foostream = Foo.extend( { foo: 10000000, bar: 17 } );
// Create instances of both types
var foo1 = new Foo();
var foo2 = new Foostream();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 testorbuster test -e browser
0.1.0
13 years ago
