On May 31, 2012, at 4:17 PM, Mark S. Miller wrote: > On Thu, May 31, 2012 at 3:14 PM, Allen Wirfs-Brock <[email protected]> > wrote: > For example, somebody might want to replace the existing apply, call, and > bind methods, with versions that throw an error when invoked on a fat arrow > or bound function. For example: > > (function replaceCall() { > if (Function.prototype.hasOwnProperty("intrinsicCall")) return; > Object.defineProperty(Function.prototype,"intrinsicCall", {value: > Function.prototype.call, configurable:true}); > Function.prototype.call = function(...args) { > if (this.isBound()) throw new TypeError("Using call method with a > bound function"); > else return this.intrinsicCall(...args); > }; > })(); > > This would seem useful for testing to see if any "bound functions" are being > used in situations that may be trying to explicitly provide a this value. > > > Why does this code not fail the criteria you already offered: it is branching > on a non-semantic private implementation decision[1] of the author of the > function, and so violating an abstraction boundary?
I don't think I argued that for isBound although I certainly would make that argument about arrow functions in general. In this case, I'm assuming a debugging scenario. Somebody is passing arrow functions through an API whose contract requires a callback function that is invokable with a dynamic this. I'm trying to find the culprit. So I write a function like the above to try to catch it. Or I just put a isBound check in the API function. It's true, that an offending function might be one that was written with a dynamic this binding but which never actually references this. That is also probably a violation of my contract. So, I may get false negative. But there is still a good change that finding positives will solve my debugging problem. Allen
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

