#Type (typejs)
A Type creation system using a lightweight prototypal inheritance implementation based on backbone.js.
jam install typejs
- Jam sets up your packages config for you, just make sure its been included
<script src="jam/require.js"></script>
or<script src="jam/require.config.js"></script>
define(['typejs', ...], function(type, ...) { ... });
orrequire(['typejs', ...], function(type, ...) { ... });
-
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, ...) { ... });
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
npm install typejs
var type = require('typejs');
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 } );
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();
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