asked by Caustic Dave from Michigan
Private variables can be created by using the ‘var’ syntax before defining the variable.
That limits its scope to within the object it was created in.
Example
function fName(){ //functions are objects in javascript var firstname = “steve”; // firstname is a private variable for the object fName } lastname = “albridge” ; // lastname is a global/public variable
Additional Reference
OOP in JS, Part 1 : Public/Private Variables and Methods
Private Static Members in Javascript
Private Members in JavaScript - Douglas Crockford
See more posts under: Resources, Tips & Tweaks
OR see posts tagged with: javascript
You may also like:
OR follow on Twitter
Twitter.com/DeDestruct
Leave a reply