View on GitHub

Creatorpattern.js

microlib to easily add the creator pattern to your class.

Download this project as a .zip file Download this project as a tar.gz file

creatorpattern.js

Micro Library to easily add the creator pattern to your class. It works in browser and node.js

How To Use It

to mixin the creator pattern in a class ``FooClass, do the following in node.js

var mixinCreatorPattern = require('creatorpattern');
mixinCreatorPattern(FooClass, 'FooClass')

or do the following in your browser

mixinCreatorPattern(FooClass, 'FooClass')

After that, FooClass honor the creator pattern. so instead of

var foo = new FooClass(2,1)

you can do

var foo = FooClass.create(2,1);

How To Include It

in node.js

 npm install creatorpattern.js

in your browser

 <script src='creatorpattern.js'></script>

API

It includes a single function mixinCreatorPattern(constructorFunction, nameOfClass)

mixinCreatorPattern(FooClass, 'FooClass')