Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
The Secret Life of JavaScript Primitives (javascriptweblog.wordpress.com)
68 points by toffeescript on Sept 4, 2011 | hide | past | favorite | 5 comments


This...is incredibly typical of JavaScript's design.


True. I'd argue that it's the best of both worlds: Unlike Java, you have access to a bunch of helpful functions on every primitive, and you can add more by modifying prototypes; and unlike Ruby, primitives are immutable, which puts a cap on the level of complexity (you could write a whole book on Ruby's string objects).


You could do something similar by having each primitive type share a global prototype á la Lua's "string" metatable. Most operations are implemented as primitives in the VM, but any non-primitive operations on primitive types go to the type's metatable.


Well, at least it does the coercion for you (unlike Java).


Good point. I remember trying to work an example in a Java textbook that involved building and printing out a times table. There were so many type coercion errors, I eventually just gave up.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: