Re: The state of Prototype's JavaScript.
| From: | Levi Morrison | Date: | Thu, 29 Mar 2012 16:20:37 +0000 |
| Subject: | Re: The state of Prototype's JavaScript. | ||
| References: | 1 2 | Groups: | php.webmaster |
| Request: | Send a blank email to php-webmaster+get-13286@lists.php.net to get a copy of this message | ||
On Thu, Mar 29, 2012 at 3:24 AM, Hannes Magnusson
<hannes.magnusson@gmail.com> wrote:
>
> On Thu, Mar 29, 2012 at 01:32, Levi Morrison <morrison.levi@gmail.com> wrote:
> > It's absolutely horrid. There's no event delegation,
> >
$() is used way to
> > much, and results of finding things that will be used again aren't saved as
> > variables. Any JavaScript gurus out there who are willing to fix it? I am
> > trying hard to clean up visual problems and don't have time to do it myself.
>
> Is there something specific you are referencing?
>
> -Hannes
Look at http://prototype.php.net/js/common.js
Consider this part:
> var $homeDownload = $('div.download .download-list');
> if($homeDownload.length > 0) {
> $homeDownload.find('li').bind('click', function() {
> window.location.href = $(this).attr('rel').replace('#',
> '');
> });
> }
It's much easier and faster to simply delegate the click handler.
Additionally, $(this).attr('rel').replace('#','') is
needlessly
using jQuery. It can easily be done with normal JavaScript and would
be faster as well.
I don't mean to offend the author(s) because the biggest thing is that
it works. Well done on that part. However, the whole file is filled
with this stuff and worse. They regularly find classes, which is an
expensive operation, and then don't save the results to a variable to
reuse again in the same function.
Levi Morrison