On Sun, Oct 30, 2011 at 1:18 PM, Jake Verbaten <[email protected]> wrote:

>
>
> On Sun, Oct 30, 2011 at 11:45 AM, Rick Waldron <[email protected]>wrote:
>
>>
>>
>> On Oct 30, 2011, at 5:58 AM, David Bruant <[email protected]> wrote:
>>
>> > Le 30/10/2011 02:35, Quildreen Motta a écrit :
>> >> (...)
>> >>
>> >>> Are we overthinking classes?
>> >>
>> >> Perhaps the reason for all this thinking about classes come from the
>> >> role constructor functions take in the language? I'm a bit sceptical
>> >> on constructors and constructor's own properties being that important,
>> >> though.
>> > I agree. Has anyone used constructor properties for "static" properties?
>> > Just considering the DOM, constants are put on the prototype and
>> > everyone sounds happy with it so far.
>> >
>>
>> In jQuery, John/we put "static" methods and properties on the jQuery()
>> function - this practice is used for anything that is not a selector match
>> operation. This includes Ajax and Deferred (among others). Considering
>> jQuery is used on >26.6million websites, it's safe to bet that practice is
>> in common use.
>>
>
> Would there be anything wrong with placing these "static methods" on the
> prototype?
>

Everything jQuery defines is done so under a single namespace, which is
actually the jQuery() "constructor" (the jQuery function actually returns
instances of itself, to avoid requiring "new")

Since all jQuery function calls return, as a new instance, an array like
object of matching elements...

jQuery(selector);

// [ node, node, node ]

...All prototype methods are expected to do DOM operations, that return the
same array like object of nodes, like so...

jQuery(selector).hide()

// [ node, node, node ]


For non-DOM operations, we put the other modules, functions and
constructors on jQuery as "static" properties (maintaining the single
Identifier namespace)

The ajax module lives at...

jQuery.ajax( options );
// returns new XHR promise

The deferred constructor...

jQuery.Deferred()
// returns new promise

The event constructor...

jQuery.Event()
// returns new event object

This pattern makes is _very_ easy for newer developers/adopters to
understand the division of functionality:

- DOM methods here: jQuery().foo()
- Everything else here: jQuery.bar()


/Rick



I presume there is also nothing wrong with placing DOM constants on the
> prototype?
>
>
>> Rick
>>
>>
>> > David
>> > _______________________________________________
>> > es-discuss mailing list
>> > [email protected]
>> > https://mail.mozilla.org/listinfo/es-discuss
>> _______________________________________________
>> es-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to