isElement and isNode in v2

2 views
Skip to first unread message

CjK

unread,
Oct 5, 2010, 4:53:43 AM10/5/10
to RightJS
Hey there,

#isElement() and #isNode() are giving me strange results in RJS 2.0
(tested in FF 3.6.x):

var e = $('comments_list');
isElement(e); => [yields nothing]
isElement(document.createElement('div')); => "DIV" - shouldn't it be
'true'?)
isElement("div"); => [yields nothing] - expected 'false'
isNode(e); => [yields nothing]
isNode(document.createElement('div')); => 1 - expected 'true'
isNode(e._); => 1 - expected 'true'
...

Either my Firebug console is broken or #isElement() doesn't behave as
it used to.

Claus

CjK

unread,
Oct 5, 2010, 5:31:57 AM10/5/10
to RightJS
Just looked at the implementation of #isElement() and something like
this would make it work:

--- before ---
[...]
return value && value.tagName; => returns tagname for elements

--- after ---
[...]
return value && !!value.tagName; => returns true for elements

But then a "negated not" might not read intuitive for everyone ;)

Claus

Nikolay Nemshilov

unread,
Oct 5, 2010, 5:52:49 AM10/5/10
to rig...@googlegroups.com
Hi Claus,

the meaning of `isElement` is the same as it was in RightJS 1, it checks if the given value is a raw dom-element and as far as I remember it wasn't changed since then.

But you have your point, I think it should be kinda like that

return value && value.nodeType === 1;

> --
> You received this message because you are subscribed to the Google Groups "RightJS" group.
> To post to this group, send email to rig...@googlegroups.com.
> To unsubscribe from this group, send email to rightjs+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rightjs?hl=en.
>

--
Nikolay V. Nemshilov
The Web-Developer

Reply all
Reply to author
Forward
0 new messages