3 ms·
Since JavaScript functions can have properties, you can construct such a function in pure CoffeeScript: ofunc =(obj = {})-> fn =(k)->@[k] bound =(arg
by Cushman 15y ago
Since 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...