Posted By

kayue on 12/31/10


Tagged


Versions (?)

Object pattern


 / Published in: JavaScript
 

  1. function theObject(){}
  2.  
  3. (function() {
  4. // private properties
  5. var THIS = this;
  6. var options = {
  7. x : 123,
  8. y : 'abc'
  9. };
  10.  
  11. // private properties setter
  12. this.define = function(key, value) {
  13. if(defined(options[key])) options[key] = value;
  14. };
  15.  
  16. // private method
  17. function defined(x) {
  18. return typeof x != 'undefined';
  19. }
  20.  
  21. // public properties
  22. this.ready = false;
  23.  
  24. // public method
  25. this.init = function() {
  26. this.ready = true;
  27. };
  28.  
  29. }).apply(theObject); // set this to MyScrip object

Report this snippet  

You need to login to post a comment.