On Thu, May 31, 2012 at 1:32 PM, Andreas Rossberg <[email protected]>wrote:
> On 31 May 2012 19:01, Bill Frantz <[email protected]> wrote: > > On 5/31/12 at 2:27, [email protected] (Andreas Rossberg) wrote: > > > >> A function is free to _document_ it as part of its > >> contract, though. > > > > > > Contracts are much more useful if they are enforced by the system, the > > language and runtime in this case. > > It can already be enforced -- as a callee, do or don't use 'this'; as > a caller, do or don't provide a receiver. What an isBound predicate > brings to the table is the ability to second-guess the contract, and > encourage callers to ignore it in cases where it is not actively > enforced by the callee. > If you reframe the problem as |this| just being another parameter, this whole debate seems quite silly to me. Any function that is written to have a |this| value be dynamic, and possibly set by the caller can be rewritten as a function that does not use |this| and simply has an extra parameter. Framing it this way, asking for an isBound method is no more useful than having a method isParamUsed(n) which checks if the nth parameter is used in the function body. There are certain cases where a dynamic |this| is a useful way to write that sort of function. If it is being used as a method, or mixed in as a method, that makes sense. The only other case that I don't actually like, but we have to live with is DOM event handlers/jQuery event handlers. Other than that, it just doesn't make sense. Any time a function is passed as an argument and used, there is an implicit contract about what that function should take as inputs, perform as side effects, and return. Whether or not it uses |this| should not really be treated any differently than asking what parameters the function expects/uses. I think it would lead to brittle code to try to ask the function if it uses |this| as some means of overloading/duck typing. That is too much introspection into the implementation. - Russ > > /Andreas > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

