6 ms·
As I mentioned in a tweet to raganwald the problem with this approach is that the object becomes opaque and can no longer be manipulated. ClojureScript allows y
by swannodette 15y ago
As I mentioned in a tweet to raganwald the problem with this approach is that the object becomes opaque and can no longer be manipulated. ClojureScript allows you to preserve the dual use.
- deleted 15y ago[deleted]
- Cushman 15y agoSince JavaScript functions can have properties, you can construct such a function in pure CoffeeScript: ofunc =(obj = {})-> fn =(k)->@[k] bound =(args...)=> fn.apply(bound, args) bound extends obj o = ofunc [1,2,3] > o(0) 1 > o[0] = 10 10 Not that I recommend this, for the obvious reasons.
- raganwald 15y agointeresting, although I think this code creates a copy of the original object’s properties rather than proxying them. Mind you, that could be what you want some times...