Private Members in JavaScript
Popularity Report
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
|||
![]() |
URL Tag Cloud
- javascript
- , programming
- , oop
- , reference
- , webdev
- , development
- , js
- , tutorial
- , private
- , web
- , howto
- , closure
- , objectoriented
- , patterns
- , oo
- , ajax
- , prototype
Bookmark History
Saved by 54 people (-20 private), first by anonymouse user on 2006-05-23
- Knightnet on 2009-11-02 - Tags javascript , development
- Jimmy87 on 2009-08-18 - Tags js-tutorial
- Ekrsulov on 2009-08-15 - Tags javascript , programming , reference , tutorial , development , webdev , web , tips
- Matteosp on 2009-08-12 - Tags javascript , Scripting , programming
- Nch_software on 2009-08-08 - Tags tutorial , web , reference , development , tips , javascript , webdev , programming , private , oop , js
Public Sticky notes
JavaScript is the world's most misunderstood programming language. Some believe that it lacks the property of information hiding because objects cannot have private instance variables and methods. But this is a misunderstanding. JavaScript objects can have private members. Here's how
Highlighted by zemoxian
Private methods are inner functions of
the constructor
Highlighted by ratbeard
Private methods cannot be called by public methods. To make
private methods useful, we need to introduce a privileged method.
Highlighted by matteosp
A privileged method is able to access the private variables
and methods, and is itself accessible to the public methods and the
outside. It is possible to delete or replace a privileged method, but
it is not possible to alter it, or to force it to give up its
secrets.
Highlighted by matteosp
A privileged method is able to access the private variables
and methods, and is itself accessible to the public methods and the
outside. It is possible to delete or replace a privileged method, but
it is not possible to alter it, or to force it to give up its
secrets.
Highlighted by ratbeard
This pattern of public, private, and privileged members is
possible because JavaScript has closures. What this means is
that an inner function always has access to the vars and parameters
of its outer function, even after the outer function has returned.
This is an extremely powerful property of the language. There is no
book currently available on JavaScript programming that shows how to
exploit it. Most don't even mention it.
Highlighted by matteosp
an inner function always has access to the vars and parameters
of its outer function, even after the outer function has returned.
This is an extremely powerful property of the language.
Highlighted by ratbeard


Public Comment
on 2006-12-20 by eliazar