Created
October 21, 2011 02:37
-
-
Save danielbeardsley/1302975 to your computer and use it in GitHub Desktop.
Examples of how to use strict-object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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