Sure, I agree that Andrea's solution is far better.

I'll even update the method I use to works with the instanceof way.

On Sep 21, 7:44 pm, aHeckman <aaron.heckm...@gmail.com> wrote:
> Mickael, I'd use Andrea's solution instead for the same reasons: any
> object could have an .is() method.
>
> On Sep 19, 5:16 am, Mickael DANIEL <daniel.mick...@gmail.com> wrote:
>
> > Hello there,
>
> > In my current project, I have a similar need to detect if a variable
> > is a jQuery object or not.
>
> > I finaly decided to add a $.isJQuery() method to jQuery namespace that
> > could acts like a regular $.isArray or $.isFunction.
>
> > Not sure, this is the best way to do this but I used something like:
> > $.isJQuery = function(o){
> >     try {
> >         // no matter the checked method, just ensure calling it not
> > raise an error
> >         o.is();
>
> >         return true;
> >     }
> >     catch (e) {
> >         return false;
> >     }
>
> > };
>
> > That did the trick for me.
>
> > Best regards,
>
> > On Sep 17, 8:04 pm, Nico <nicolas.deve...@gmail.com> wrote:
>
> > > Hi,
>
> > > I first posted this message on the jquery-en group, but it should
> > > probably be posted here, so here am I.
>
> > > In some cases, I have to check if a variable is a jQuery object or
> > > not. Usually, to check a variable type, I use the "constructor"
> > > property
> > > (when I can't use typeof, which is not accurate).
> > > In case of jQuery, the constructor property equals Object, so I can't
> > > use it.
> > > When I create a jQuery Object, it's known by javascript as an object,
> > > and it behaves like a function.
>
> > > Would it be possible to add something so we could get a true with this
> > > example :
>
> > > $([]).constructor === jQuery
>
> > > This would be great, no ?? The only change to do is to add in the
> > > beginning of jQuery.fn.init method the line :
>
> > > this.constructor = jQuery;
>
> > > This way, all jQuery's objects "constructor" property equals jQuery. I
> > > quickly tried this, and I met no bugs.
>
> > > Any arguments against this ?
>
> > > Nico
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to