GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing en.wikibooks.org — JavaScript/Access control - Wikibooks, open books for an open world
Access ControlJavaScript does not provide a direct means to control access to internal variables, however, it is possible to restrict access to some variables. By default, variables within an object are public and can be modified anywhere in the code. As such, any programmer that uses the code in the future may change the internal state of the object unexpectedly, which has the potential for problems. While the easiest protection against this is to properly document your code (e.g. comments showing how to use the object), there are cases where you want to block direct access to a variable. To declare and use a variable as private, there are two steps required:
function MyObject() { this.publicNumber = 10; // Public field. var privateNumber = 20; // Private variable. this.getPrivateNumber = function() { return privateNumber; } } testObject = new MyObject();
Hidden category: |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |