@thomas

all valid points and interesting links. Thanks for the insight.

To my defense however I want to state again that I have not devised this
API.

It's the official API of D3

   - v3
   https://github.com/d3/d3-3.x-api-reference/blob/master/Arrays.md#d3_bisector
   - v4 https://github.com/d3/d3-array/blob/master/README.md#bisector


so it is not possible to change the API. If I take a step back (not
realistic) and say that I won't use D3 at all because it has such a bad API
(not true. Generally I enjoy the D3 very much.) I am sure I will hit
similar snags in other js libraries.

So... better the devil you know....

     Vassilis


On Wed, Jun 28, 2017 at 4:12 PM, Thomas Broyer <[email protected]> wrote:

>
>
> On Wednesday, June 28, 2017 at 2:21:16 PM UTC+2, Vassilis Virvilis wrote:
>>
>> I am not following the implementation details and I cannot judge on the
>> compromises front.
>>
>> But from a user standpoint this should be implemented because a
>> @JsFunction should generate a js function()  and a js function() happens to
>> have a length member by specification (see https://developer.mozilla.org/
>> en/docs/Web/JavaScript/Reference/Global_Objects/Function/length )
>>
>> Otherwise @JsFunction is not a js function() but something callable
>> instead.
>>
>
> GWT generates a function, but a function with an empty formal parameter
> list (and as a result a length of 0), because it simply uses 'arguments':
> https://github.com/gwtproject/gwt/blob/2.8.1/
> dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/
> gwt/lang/Runtime.java#L158-L169
>
>
>> Given the dynamic number of javascript I expect that these kind of checks
>> to be common enough to warrant the effort.
>>
>
> One could argue the reverse: due to the dynamic nature of JS, 'length' of
> a function isn't reliable, and you'd be better off using distinct APIs
> rather than driving behavior by inferring things from inputs, or more
> precisely be explicit with your intent.
> It easily fails you, as soon as you wrap a function to bind, curry,
> memoize it, whatever, using a generic factory (one that uses 'arguments'
> along with Function.prototype.apply or Function.prototype.call; one that
> specifically doesn't use Function.prototype.bind).
> Have a look at the Function.prototype.bind polyfill from the MDN for
> example: https://developer.mozilla.org/en-US/docs/Web/
> JavaScript/Reference/Global_Objects/Function/bind#Polyfill
> Any code targeting IE8 or older (that doesn't necessarily mean new code)
> would need this polyfill, and the returned function (fBound) has a length
> of 0, irrespective of the length of the function to bind.
> There's a polyfill for Function.prototype.bind that returns a function
> with the correct 'length', but it uses new Function() with a string body:
> https://github.com/Raynos/function-bind/blob/
> 83e639ff74e6cd6921285bccec22c1bcf72311bd/implementation.js#L38 so it'd
> break most CSP. While IE8 doesn't support CSP (so it's OK for this
> particular polyfill), that however means you cannot use such a trick for
> other things you'd like to do with a function (such as memoizing it: for
> example, https://github.com/caiogondim/fast-memoize.js returns a function
> with length 0 too).
>
> --
> You received this message because you are subscribed to the Google Groups
> "GWT Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/google-web-toolkit-contributors/e12e8c02-c6f0-
> 4818-aaee-fb564935e8ec%40googlegroups.com
> <https://groups.google.com/d/msgid/google-web-toolkit-contributors/e12e8c02-c6f0-4818-aaee-fb564935e8ec%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Vassilis Virvilis

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAKbOjEwwD-hDNBt8QEE2h0k74yxpFWdCsX5J5Lh3%3DsHeGptDcw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to