Skip to content

Instantly share code, notes, and snippets.

@danielbeardsley
Created October 21, 2011 02:37
Show Gist options
  • Save danielbeardsley/1302975 to your computer and use it in GitHub Desktop.
Save danielbeardsley/1302975 to your computer and use it in GitHub Desktop.
Examples of how to use strict-object
// https://github.com/danielbeardsley/strict-object
// Create a new person type
var Person = StrictObject.define('name', 'age', 'country');
// Instatiate a Person
var pete = new Person();
// set properties using functions
pete.name('Peter');
// get properties using functions
console.log(pete.name());
// property setters return the target object and are thus chainable
pete.name('Peter')
.age(26)
.country('Uzbekistan');
// retrieve the properties as an object
console.log(pete._toObject()); // {name: 'Peter', age: 26, country: 'Uzbekistan'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment