Re: ISSUE-41/ACTION-97 decentralized-extensibility

On Wed, Oct 28, 2009 at 8:07 PM, Tony Ross <tross@microsoft.com> wrote:
> On Wednesday, October 28, 2009 at 2:15 PM, Jonas Sicking wrote:
>> On Tue, Oct 27, 2009 at 6:07 PM, Tony Ross <tross@microsoft.com> wrote:
>> > The nature of script and these libraries provides consumers with an
>> > adequate means of resolving object name conflicts should they arise.
>> > The global variable for these libraries can typically be reassigned to
>> > another variable without impacting the behavior of the library itself.
>> > Thus should two names ever conflict, a page author can just rename the
>> > first before the second library loads.
>>
>> Hmm.. Not quite sure I follow what you're saying. Do you have any
>> examples?
>
> Link from the homepage of jQuery's website which illustrates some examples (though mostly focused on jQuery's use of '$'):
> http://docs.jquery.com/Using_jQuery_with_Other_Libraries

Interestingly, jQuery purposely invaded that name-space.  The use of $
was already widespread as a short form of getElementByID, and I
Prototype was already using it to upgrade element nodes as well.
jQuery overlapped itself on that name, and thus deliberately made it
easy to swap it out if necessary (you can always use jQuery() instead
of $(), and it is careful to save the old definition, if any, of $ so
that you can unclobber it if you want).  jQuery docs also stress an
idiom for allowing library authors to use the short form without
conflicts.

Many libraries do build on the single-global-object method of reducing
namespace pollution, but I don't think many were as careful as jQuery.
 (They may be more careful now, I dunno.)

~TJ

Received on Thursday, 29 October 2009 01:59:15 UTC