Le 02/11/2011 16:15, Quildreen Motta a écrit : > On 02/11/11 13:01, David Bruant wrote: >> Le 02/11/2011 14:26, Jeremy Ashkenas a écrit : >>> (Full Disclosure: I'm still very opposed to const, private, and >>> their object-lockdown friends, ....) >> >> Regarding "const", it's an optional keyword basically telling the >> interpreter "hey, the value isn't suppose to change at runtime, >> please ensure it!". It prevents bugs of mistakenly redefining >> something that shouldn't be redefined. Why are you opposed to this? > Yeah, immutability and referential transparency are wonderful things. > I wish JavaScript developers would rely more on it, it makes things > saner to work with. Though is `const' the same as Object.freeze(thing) > when `thing' is an object? Or does it just ensure that the slot in the > object isn't reassigned? It depends on the context. If const is used in front of a variable, the variable value will remains constant. The definition of a const class is given by Brendan (https://gist.github.com/1332193 ~l.239). There is a semantics of const functions I don't remember.
>> Regarding "private", I'm puzzled. Having private attributes in >> objects is necessary to implement encapsulation and get all the >> benefits of good object-oriented practices. > I still think `private' is quite overrated. It gets terrible if you > want to test something and the developer went through all the trouble > of making proxies to access everything, as well as making everything > stateful. If you stab me, I won't accuse the knife. I agree with what you describe, but it's the problem of the developer misusing the feature rather than an inherent problem of the feature itself. > That said, there are some valid use-cases for it... I guess? Encapsulation? Stability of interfaces? Better readability? The use case is more about code quality and expressiveness rather than adding a new capability to the language. David
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

