Geeks With Blogs
Phubar Baz Musings of an HTML5 Programmer June 2013 Entries
Chainable Property Pattern
Here's a pattern I use a lot to encapsulate properties in JavaScript objects. I call it the Chainable Property Pattern because it is used to define get/set operations for properties that can be chained together into one statement. We start with an object with a private variable. function MyObject(){ var count = 0; Next we create a public property accessor method. this.count = function(newCount) { if (arguments.length) { count = newCount; return this; } return count; }} Let's take a look at how this ......

Posted On Thursday, June 13, 2013 10:47 AM

Copyright © PhubarBaz | Powered by: GeeksWithBlogs.net