4 ms·
Yeah, at least this way you have control over which properties are methods. Also, if you really prefer angular.js style of tracking dependencies, this plugin m
by gdrulia 13y ago
Yeah, at least this way you have control over which properties are methods.
Also, if you really prefer angular.js style of tracking dependencies, this plugin makes the trick http://blog.stevensanderson.com/2013/05/20/knockout-es5-a-plugin-to-simplify-your-syntax/ http://blog.stevensanderson.com/2013/05/20/knockout-es5-a-pl...
- mattmanser 13y agoThanks, looks good. I know it sounds pedantic but it's not 'prefer', it's that the properties as methods is fundamentally changing the way the language works and is very brittle.
- klibertp 13y agohttp://en.wikipedia.org/wiki/Uniform_access_principle http://en.wikipedia.org/wiki/Uniform_access_principle In short, it doesn't matter which it is - a method or an attribute - as long as it's consistent. What fundamental changes to the language you see when using methods instead of plain attributes? Aside from the fact that setter and getter methods in JS are bindable while attribute access is not.
- mattmanser 13y agoYou're kinda arguing against yourself as the code won't be consistent. You're changing a part of your code but not all of it and it just leads to brittle code as you're never sure what you're working with, especially in a dynamically typed language like javascript with terrible support for editor behaviour sniffing. Every time you have an object you have to remember whether it's a normal JS object or a properties-as-methods object. Using knockout to handle your view models doesn't magically change the rest of your code. All the other code you write and libraries you use will be using properties the standard way. Secondly, the uniform access principle (which you seem to misquoting? It's not about consistent access by type, it's about all types having identical methods of access). It comes across as something an academic would propose because it's intellectually enticing but practically detrimental. Think of it like changing a, it, the, we, you, our, etc. all to be o. Yeah, now you can change nouns freely, but the syntax is a signal and the difference is useful. A method is conceptually supposed to be different to a property and so it should look different. Javascript's bad enough for readability with everything being a function. Whether you agree with it or not, in the end it's simply not how javascript works. Methods and properties are accessed differently.
- noir_lord 13y agoThis is amazingly good and very elegant.