From: Matt Kruse on
On Dec 8, 3:50 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
> > obviously the attr() method is meant to only set string properties.
> It is not set up, nor is it designed for string properties.

Oops, meant to say attributes.

> Which of
> these will check a box in jQuery?
> attr(el, 'checked', true);
> attr(el, 'checked', 'true');
> attr(el, 'checked', '');
> attr(el, 'checked', 'checked');

I don't even know, because I'm not sure why anyone would do that.

> I've seen all of them in practice and lots of questions about this and
> similar issues in the various jQuery support forums, blog posts, etc.

Agreed. It is a side-effect of people trying to "jQuery-ize"
everything in their code. It's ridiculous to use a lib method like attr
() just to check a checkbox.

Although, I have done something like this:

$(':checkbox[name=foo]').run("this.checked==true");

run() is obviously a little eval wrapper that I plugged into jQuery. I
like using jQuery to conveniently grab a set of elements that I want
in order to manipulate them, but I don't really like it's methods that
do the manipulation.

> I know the first works for most, except for XML, which jQuery seems to
> want to support with this method.

I think they try to support XML because of XHTML. It seems terribly
misguided, and I don't know what rationale they have for doing it, if
any.

> Glad you liked the review (as much as I could be glad about it).  Now
> stop using this junk.  :)

I will when there is a suitable replacement that fills a variety of
needs better than jQuery does (despite its problems, if you use jQuery
only for the things it does do well and avoid the problem areas, it's
very convenient). How's the Dojo work coming?

I would really like to see a long, formal analysis of jQuery. Since it
still seems to be the dominant js framework available, I would like to
have a polished, well-written critique of its design decisions and
code quality, pros and cons, so everyone could properly evaluate the
library and decide if and when to use it. If it were written as a
wiki, it would allow multiple contributors to this group to refine the
writing and would probably become a valuable resource for the
thousands of developers on the web who are using the library.
Unfortunately, those who have the knowledge and expertise to write up
such an analysis rarely have the time or interest in doing so. So the
blind following the blind continues...

Matt Kruse
From: David Mark on
On Dec 9, 11:19 am, Hans-Georg Michna <hans-
georgNoEmailPle...(a)michna.com> wrote:
> David,
>
> it is really a pity. The fundamental ideas of jQuery,
> particularly to use CSS selectors and a functional style of
> programming, are sound, as far as I can tell, and they often
> allow you to write as a one-liner, what would otherwise be half
> a page of JavaScript code.

I suppose any library of functions can make that claim. ;) I don't
care for querying by CSS selectors though. To do it in older browsers
requires a heart-stopping amount of error-prone code. The typical
jQuery line takes 10,000 function calls to do what a few lines of JS
could do with standard host methods. I think reliability trumps the
number of lines of code every time (and what do lines of code matter
if the end result is minified?)

>
> Why is nobody writing a competing library, maybe a good subset
> of jQuery, but without the foul spots? There is an obvious need
> for such a critter, otherwise people wouldn't flock to jQuery,
> and I wouldn't like to miss it either.

Most professionals who write JS can see the folly in choosing one
monolith in advance for every context, so they don't write such
things. I made an exception a couple of years back (Google "browser
scripting library" and click the first hit). It is a functional API
with an optional jQuery-like (but competently designed) "chainable" OO
interface (or you could write your own that is exactly like jQuery if
that's what you really want). I don't recommend using such interfaces
as they just slow things down, but at least mine is a fairly
"unobtrusive" layer.

I don't really care to market a free library, but if anyone cares to
help with the documentation, evangelizing, etc. they have whatever
limited support I can muster.

>
> Why isn't anyone sending John Resig a big, fat set of test
> cases?
>

What good would that do? He needs to understand why. It was
explained to him years ago (by me). He didn't get it then and
apparently he's still in the dark today. :(
From: Garrett Smith on
Matt Kruse wrote:
> On Dec 8, 3:50 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
>>> obviously the attr() method is meant to only set string properties.
>> It is not set up, nor is it designed for string properties.
>
> Oops, meant to say attributes.
>
As in:
| obviously the attr() method is meant to only set string attributes.

jQuery.attr has specific handling for many odd cases. What does attr
have to do with:

| if ( name == "selected" && elem.parentNode )
| elem.parentNode.selectedIndex;

That's a boolean property, not an attribute, right?

Or:
| if ( !jQuery.support.opacity && name == "opacity" ) {
| if ( set ) {
| // IE has trouble with opacity if it does not have layout
| // Force it by setting the zoom level
| elem.zoom = 1;

A method dealing with attributes working to do modify style properties
of objects, then providing workarounds for IE, not checking to see
currentStyle.hasLayout (the object migh have a layout already).

That method is doing way too much.

>> Which of
>> these will check a box in jQuery?
>> attr(el, 'checked', true);
>> attr(el, 'checked', 'true');
>> attr(el, 'checked', '');
>> attr(el, 'checked', 'checked');
>
> I don't even know, because I'm not sure why anyone would do that.
>

Probably to try and check a checkbox. What attr does is not entirely
distinct. It's sometimes attributes, other times properties.

>> I've seen all of them in practice and lots of questions about this and
>> similar issues in the various jQuery support forums, blog posts, etc.
>
> Agreed. It is a side-effect of people trying to "jQuery-ize"
> everything in their code. It's ridiculous to use a lib method like attr
> () just to check a checkbox.
>
> Although, I have done something like this:
>
> $(':checkbox[name=foo]').run("this.checked==true");
>
> run() is obviously a little eval wrapper that I plugged into jQuery.

That sounds dangerous. Calling eval, you know the thisArg and Variable
is from the calling context. Eval works differntly in ES5, but that's on
the horizon as far as implementations are concerned. Passing in
something that is used in the calling context would be modifying variables.

[sni[p]

>
>> Glad you liked the review (as much as I could be glad about it). Now
>> stop using this junk. :)
>
> I will when there is a suitable replacement that fills a variety of
> needs better than jQuery

Such as?

> I would really like to see a long, formal analysis of jQuery. Since it
> still seems to be the dominant js framework available, I would like to
> have a polished, well-written critique of its design decisions and
> code quality, pros and cons, so everyone could properly evaluate the
> library and decide if and when to use it. If it were written as a
> wiki, it would allow multiple contributors to this group to refine the
> writing and would probably become a valuable resource for the
> thousands of developers on the web who are using the library.
> Unfortunately, those who have the knowledge and expertise to write up
> such an analysis rarely have the time or interest in doing so. So the
> blind following the blind continues...
>

If you really want it, then do it. I'll provide feedback on it and
comments to your efforts.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Garrett Smith on
Garrett Smith wrote:
> Matt Kruse wrote:
>> On Dec 8, 3:50 pm, David Mark <dmark.cins...(a)gmail.com> wrote:
>>>> obviously the attr() method is meant to only set string properties.
>>> It is not set up, nor is it designed for string properties.
>>
>> Oops, meant to say attributes.
>>
> As in:
> | obviously the attr() method is meant to only set string attributes.
>
> jQuery.attr has specific handling for many odd cases. What does attr
> have to do with:
>
> | if ( name == "selected" && elem.parentNode )
> | elem.parentNode.selectedIndex;
>

Note that the statement inside the if test is entirely useless, as it is
not assigned to anything.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Stefan Weiss on
On 11/12/09 08:35, Garrett Smith wrote:
> Garrett Smith wrote:
>> jQuery.attr has specific handling for many odd cases. What does attr
>> have to do with:
>>
>> | if ( name == "selected" && elem.parentNode )
>> | elem.parentNode.selectedIndex;
>>
>
> Note that the statement inside the if test is entirely useless, as it is
> not assigned to anything.

The two lines above the quoted part are:

// Safari mis-reports the default selected property of a hidden option
// Accessing the parent's selectedIndex property fixes it

It would appear that this was intended as a bug workaround, and that
reading the selectedIndex property is all that's required. Still, it's a
strange thing to do, and could very well be optimized away by a minifier
tool or by the JS engine itself.


stefan