snowman ☃
Immutable, inheritable objects with information hiding.
The snowman()
function creates factory functions for objects with the
following features:
- Constant private, protected and public members
- Private, protected and public static members
- "Super" via
Object.getPrototypeOf
- Totally immutable objects via
Object.freeze
These features allow data to be shared in an exclusive manner, without exposing
it for modification or even readability. Implementation details no longer leak,
sparing projects from additional maintenance and documentation. Data is more
secure, if not completely locked-away, from malicious 3rd-parties. No more
object._pinkyPromise
.
Let it snow, let it snow, let it snow... ❄
Installing
Browser:
bower install snowman
Node:
npm install snowman
Usage
Via browser global:
{ var factory = ;}windowsnowman;
AMD:
;
CommonJS:
var snowman = factory = ;
Examples
{ 'use strict'; var personFactory = potentiallyMoreExperiencedFactory = joe = sam = bobby = ; console; // "Joe" console; // undefined console; // undefined joe; // The name's Joe. joe; // It's my birthday! How did you guess? joe; // I'm 25. console; // "Sam" console; // undefined console; // undefined sam; // The name's Sam. sam; // It's my un-birthday. sam; // None of your business. bobby; // I'm 44. };
For more examples, see tests/
.
Development
# Watch for changes and run tests. grunt watch # Lint, test, build. grunt