Saturday, September 19, 2009

Be Privileged And Skip JavaScript's Prototype

Reading Pro JavaScript's second chapter "Object-Oriented JavaScript" reminded me that I do not use the prototype property to add public methods to a JavaScript object. I use "Privileged Methods" (pg 36) instead.

In the book, John refers to Douglas Crockford's JavaScript site and the Privileged technique described in the web page titled Private Members in JavaScript. I quote from the web page:
"A privileged method is able to access the private variables and methods, and is itself accessible to the public methods and the outside."

If you are looking for more code examples beyond what Douglas Crockford provides, Quizzpot shows more code examples at Private and privileged methods in JavaScript

Using Privileged Methods is a great technique when coding JavaScript objects. Have fun doing it.

1 comment:

  1. This is an amazing blog,it gives very helpful messages to us.Besides that Wisen has established as Best Javascript Training in Chennai . or learn thru JavaScript Online Training India. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete