Re:Go's power is in emergent behavior
by md224 on Sunday April 27, 2014 @05:52AM
(#7654526)
Yeah, it looks like their solution is just creating a function object whose interface-required method calls the object itself (or at least that's my OOP-centric interpretation). You could do something like that in Javascript (minus the interface, obviously):
I wonder if this is a useful pattern in JS. Can't recall ever seeing it in practice.
[ Parent
| on HN ]
It's useful in go, because it means you can trivially turn a bare function into a type that fulfills an interface, which makes your function more flexible - it can easily take either a type with a method or just a method.