On Mar 15, 8:09 am, kangax <[email protected]> wrote:
> On Mar 15, 10:35 am, Tobie Langel <[email protected]> wrote:
> [...]
>
> > The difficulty of abstracting your solution comes from the need for
> > the bound function to keep a reference to the original length of the
> > array so a to reset it before passing it to the original function.
>
> > I suspect that the cleanest solution might be to keep a generic array
> > updating method and reset the original before calling it.
>
> Isn't that what your "internal" (used with `Function.prototype`
> extensions) `update` does?
>
> function update(array, args) {
>     var arrayLength = array.length, length = args.length;
>     while (length--) array[arrayLength + length] = args[length];
>     return array;
>   }
>
> --
> kangax

I've put together a new set of tests to explore this avenue of thought
a bit further: http://www.broofa.com/Tools/JSLitmus/tests/PrototypeBind2.html
.  Very similar to my previous test page, but I've dropped the
approaches that we're not really interested in at this point, and kept
just the two Kangax variants we've discussed.  I've added a new "Less
Improved" test in which I use put the code that marshals the args
array into a separate _update() method.  (Note that my _update() is
noticeably different from Kangax's, above, since we I had to pass in
the original length of 'array', and also set the array.length)

The new test is called "Less Improved" because it is noticeably less
performant, especially on Firefox where it is only 1/4 as fast.  Here
are the results I get for various platforms:
IE/WinXP - http://tinyurl.com/d442g3
Firefox/MacOSX - http://tinyurl.com/db3lga
Safari/MacOSX - http://tinyurl.com/df4tdx
Opera/MacOSX - http://tinyurl.com/ck4a4o
Chrome/WinXP - http://tinyurl.com/ckt535

Since the overhead of the additional function call is a significant
performance hit on Firefox and IE I'll suggest that we _not_ take this
approach?  At least, not where performance is a paramount issue (in
bind()).  Instead, the code should be kept inline.  I know this is a
bit heretical, but I believe performance trumps DRY in this case.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to