3 ms·
Even though JS doesn't have language constructs for public/private, there are a number of different ways to write modules with hidden members by use of closures
by mryall 15y ago
Even though JS doesn't have language constructs for public/private, there are a number of different ways to write modules with hidden members by use of closures.
Crockford explains with some examples here:
http://javascript.crockford.com/private.html http://javascript.crockford.com/private.html
- ryan-allen 15y agoI'd say that using closures and functions to create public apis with internal private structure does qualify it to have 'language constructs for public/private'. It just took programmers collectively over 10 years to figure it out. I blame the 'new' keyword in JS, it feels completely grafted on after the fact. Lua has been using this method of designing modular programs for years.
- Tomek_ 15y agoI know you can do it, but it produces quite an overhead and it's ugly. But that's for another discussion ("sad things in JS" maybe) - here my main point was that, no, public/protected/private is not a dumb idea in dynamic languages.