Jörn Zaefferer schrieb:
>> I still think that using a namespace and providing a short cut like $A
>> is the best way to handle this, instead of extending the element or
>> prototype. I think we could even get chaining to work properly if we
>> really wanted too. We could also probably provide a way to extend the
>> prototype if users really wanted it.
> 
> I'd really like to hear other's opinions about this topic. John? Mike? Klaus? 
> If you read this: Say something!
> 
> I think jQuery is a lot about promoting best practice. Find the best approach 
> for a certain aspect and promote that approach, instead of providing every 
> way and as much flexibility as you can think of. The latter used to happen a 
> lot in the java enterprise enviroment and is pretty ugly.
> 
> It's great to have to opportunity to discuss it here at expense :-)

I've read once somewhere (was it Crockford?) that you "should not extend 
a language with its own features". I'm not that strict and think as long 
as we don't touch the object we're fine. Using for/in on an array is bad 
style and yes, I don't think jQuery should take into acount other's bad 
coding style. Making jQuery dummy safe would be an endless process, so - 
agreed - better promote best practice and be helpful on the list if 
questions appear.

It seems to be a trend to use and if required port the new Array 
functions of JavaScript 1.6. I like that if it's done wisely:

if ( !Array.prototype.forEach ) {
   // add sugar
}

That won't overwrite existing implementations. That could also be done 
for other additional functions. Although I already foresee the question: 
"Why, your Array.whatever function does not work as described in the 
documentation" on the list, if some other library uses the same name. 
But at least for the 1.6 methods there should be no clash.

Dustin Diaz did that already here:
http://www.dustindiaz.com/sugar-arrays/

I like the prototype approach more than using a helper method like $A 
etc. and/or the namespace approach, because to me it kind of feels more 
natural using a method on the array object immediatly.

If we don't go that route I'm for the namespace implementation, that 
looks as the cleanest solution to me.

$.array.whatever() is better readable to me than $A...


Hey, very clever to extend the objects itself! Does it make sense to 
have chainability for these methods? I can't see how to use that at the 
moment.


-- Klaus



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to