I also love how the ko.observable doesnt feel as magical as the angular binding. It makes me feel alot more in control
I also love how the ko.observable doesnt feel as magical as the angular binding. It makes me feel alot more in control
var myViewModel = {
personName: ko.observable('Bob'),
personAge: ko.observable(123)
};
myViewModel.personName() //get
myViewModel.personName('Mary') //set
Makes my eyes bleed.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-pl...
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.
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.
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.
At least with knockout you know you are always out of context and have to use the getters/setters.