6 ms·
At the end of the article, it is demonstrated that this can happen even with strict equality by overriding the getters. Any language with getter/setter support
by maxbucknell 12y ago
At the end of the article, it is demonstrated that this can happen even with strict equality by overriding the getters. Any language with getter/setter support can do this. Operator overloading can be used for even nefarious ends.
The point is that side effects in code are dangerous, and can be used to mislead a reader.
If this happens, it is not the fault of JavaScript. Anyone who writes code like that for purposes other than demonstration or learning is a moron.
- mikeash 12y agoNot all languages with getter/setter support will invoke them automatically like this. For example, it's not possible in Java or Objective-C to make an expression of the form a == b, where a and b are plain variables, have any side effects.
- tyilo 12y agoIn Obj-C you can if you would allow `a.prop == b.prop`.
- mikeash 12y agoSure, but then it's obvious that you're doing something beyond an equality comparison.
- jacalata 12y agoDo you mean it is obvious to people who know objective C? I've never used the language, but its not obvious to me just from the other c-family languages I know.
- mikeash 12y agoYes, if you know Objective-C. If you don't know it, I wouldn't expect you to immediately grasp anything about the behavior implied by a snippet of it.