Most plugins will return a this.each(function(){... call, so if there
are no matching elements, nothing will get executed, practically zero
overhead. But that is a different question, in case the plugin itself
doesn't exist you'll get the 'myplugin is not a function' error. If
you're in a place where that could happen, the second approach is best
without a doubt.

- ricardo

On Mar 27, 10:36 am, Enrique Meléndez Estrada <emelen...@ita.es>
wrote:
> I have a curiosity question,
> Imagine I want to apply a function (myplugin()) to a jquery object if
> this has a particular className.
> Imagine that NO jquery object has 'myclass' associated and myplugin()
> NOT exist.
> so
> $this.filter('.myclass').length == 0
> and
> $this.is('.myclass') == false
>
> 1. most common possibility: throws an error (myplugin doesn't exist: It
> tries to bind an inexistent function to ZERO)
> $this.filter('.myclass').myplugin()
>
> 2. alternative possibility: no error (does nothing)
> $this.is('.myclass') && $this.myplugin()
>
> Now imagine that myplugin() EXISTS (and you have lot of lines of this
> kind: different filters and methods)
> My question: which possibility (1 or 2) is the best in the meaning of
> time speed and overheads?
>
> thanxs
>
> --
> Enrique Meléndez Estrada (976 01 0083)
> Dpto. Servicios Informáticos
> Área Organización y Servicios Internos
> INSTITUTO TECNOLÓGICO DE ARAGÓN
> c/ María de Luna 8, 50018, Zaragoza (Spain)
> emelen...@ita.es -http://www.ita.es
>
>  emelendez.vcf
> < 1KViewDownload

Reply via email to