Posted By

rccc on 11/13/09


Tagged

javascript oop


Versions (?)

javascript private and privileged members


 / Published in: JavaScript
 

URL: http://www.crockford.com/javascript/private.html

  1. /* Public */
  2.  
  3. function Constructor(...) {
  4.  
  5. this.membername = value;
  6.  
  7. }
  8. Constructor.prototype.membername = value;
  9.  
  10. /* Private */
  11.  
  12. function Constructor(...) {
  13.  
  14. var that = this;
  15. var membername = value;
  16.  
  17. function membername(...) {...}
  18.  
  19. }
  20.  
  21. Note: The function statement
  22.  
  23. function membername(...) {...}
  24.  
  25. is shorthand for
  26.  
  27. var membername = function membername(...) {...};
  28.  
  29. /* Privileged */
  30.  
  31. function Constructor(...) {
  32.  
  33. this.membername = function (...) {...};
  34.  
  35. }

Report this snippet  

You need to login to post a comment.