Hacker News new | ask | show | jobs
by emn13 4709 days ago
If getters/setters aren't available, I still vastly prefer plain functions (e.g. knockout) to the stringized setter.

I mean, why would

   model.set('someProp', 'someVal');
   x = model.get('someProp');
be better than

   model.someProp('someVal');
   x = model.someProp();
And the second one is likely to perform better, allows better tooling support (nice to have), is shorter, and allows representing a property as a concept in itself `model.someProp`. You can still access a property with a variable name in the (unusual) case you need to.

If you really insist on explicit set/get, then you can still have...

   model.someProp.set('someVal');
   x = model.someProp.get();
Which still has no downside I can think of, and since this is JS, if you have a variable prop name, you can fall back to...

Pretty please, will the unnecessary strings die?