javascript private and privileged members


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your 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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.