4 ms·
> For instance, passing a method as an argument will do awful things unless you bind it to a this first. That was true long before classes arrived.
by pwdisswordfishc 3y ago
> For instance, passing a method as an argument will do awful things unless you bind it to a this first.
That was true long before classes arrived.
- mst 3y agoIt continues to sadden me that the implicit this injection happens only on direct invocation - let res = obj.method(arg); and let m = obj.method; let res = obj.method(arg); being different things seems like an unfortunate trade-off (though not knowing the full reasons it was chosen to be that way makes me wary of assuming it was the wrong decision overall). I've been known, for things where the object is e.g. a bag of components, to loop at construction time and replace all of my methods with pre-bound copies of themselves, but having to make a conscious decision as to whether I need to introduce that extra code (and work for the runtime per-instantiation) still makes me grumble to myself every time.
- llamaLord 3y agoCan you explain wrist you mean by those two examples being different things? Do you mean that 'res' evaluates to a different result in each? Or that when you call 'object.method()' vs calling 'm()' you would get a different 'this' context?
- mst 3y agoI completely messed up one of the examples, sorry. I meant the 'this' thing - a sibling comment to yours contains the correct code.
- majou 3y agolet m = obj.method let res = m(arg)
- mst 3y ago-facepalm- Thank you.