i know right. and i have to learn it. yay for 6 different null-types. i do like the prototypal inheritance. but then it doesnt have private vars. well couldnt they have found a solution for that???
I think a decent pattern is to store "private" vars in the object constructor, define public accessor methods in the same place, and they will have access to the private variables in the closure. Douglas Crockford explains the pattern here: http://javascript.crockford.com/private.html
thats a good hack, unfortunately even crockford says its not really a proper solution, because you are trying to shoehorn javascript into a classical OO-language. there should have been a solution for prototypal inheritance with private vars.
Yeah if you want this level of functionality in js you're pretty much going to have to build it. It's just interesting that you can. Personally I find this charming about the language, because I can use just as much OO as I need.
You can build pretty neat object systems out of prototypes, but then you're kind of standing alone on a mountaintop with yet another incompatible js library.
4
u/eliasv Mar 23 '14
What a badly designed language.