> We've extended all objects including numbers to respond to the bar function.We can provide more specific implementations at anytime, i.e. by using extend-type on string, array, Vector, even your custom types
>> We've extended all objects including numbers to respond to the bar function.We can provide more specific implementations at anytime, i.e. by using extend-type on string, array, Vector, even your custom types
>Mimicking that in javascript:
>This is totally safe (except for oldIE)
No, not in his definition of safe it isn't. That's just monkeypatching -- the new functions are visible everywhere in the program, and it's entirely possible to be stung badly by name collisions. The ClojureScript version doesn't have these problems -- the protocol only exists in the namespaces where it is defined or imported.
Mimicking that in javascript:
More specific implementations can be defined on the other prototypes. This is totally safe (except for oldIE).Making objects behave as functions (actually the opposite) is also possible:
or And no, I have no idea how this could be useful...