isChildNode(node, node) --> true
isParent(node, node) --> false
Is it not pointless to keep both functions around? Since isChildNode()
is more tested (and probably more used), I'd suggest removing
isParent() from the API before the 1.4 release. Possibly, in order to
simplify the transition, we could just alias isParent to isChildNode
(and remove the API doc specification so that noone will use it from
now on).
Opinions?
Cheers,
/Per
PS. I just discovered that Google Groups silently dropped all my
emails that used another sender address, so I'm currently resending
all my recent postings. Hence the sudden email bombing...
Cheers,
/Per
Personally, I agree that it seems pointless to have isParent around when
isChild will do the same thing. I don't even think the alias is needed, if
someone wanted the semantics that would provide, let them alias it
themselves, I say.
There is my opinion, for what little it is worth.
Jason Bunting
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com
> Version: 8.0.173 / Virus Database: 270.8.1/1730 - Release Date: 10/17/2008
> 8:07 AM
You can merge the functions by using an additional flag (e.g.
direct=true), but it's probably easier to have two separate functions.
However, they certainly need better names & documentation.
-- Christoph
Per Cederberg schrieb:
On Sat, Oct 18, 2008 at 12:23 AM, Jason Bunting
<thurber...@hotmail.com> wrote:
> Who is Noone? :P
Sigh... The endless joys we bring you native English speakers... ;-)
On Sat, Oct 18, 2008 at 5:54 PM, Christoph Zwerschke <ci...@online.de> wrote:
> Hm, if I read the code correctly, then there is another difference,
> namely that isChildNode also returns true if the second node is not the
> direct parent, but also for grandparents and any ancestors. So it should
> be actually renamed to something like isDescendant or isAncestor.
Both actually do that. But isParent() does it through recursion
instead of iteration:
isParent: function (child, element) {
var self = MochiKit.DOM;
if (typeof(child) == "string") {
child = self.getElement(child);
}
if (typeof(element) == "string") {
element = self.getElement(element);
}
if (child == null || element == null) {
return false;
} else if (!child.parentNode || child == element) {
return false;
} else if (child.parentNode == element) {
return true;
} else {
return self.isParent(child.parentNode, element);
}
},
I totally agree on the naming. Should be named as you propose, but I
don't see us changing the API right now though... :-(
Cheers,
/Per
-bob
Ah, right. Overlooked the recursive call in the last line of isParent.
Then both names are really misleading. It's completely unusual to call a
not direct ancestor "parent" or a not direct descendant "child".
And there's really no reason to keep them both, or making one the alias
of the other. If both functions are there, then they should have least
swapped arguments, like here:
http://publib.boulder.ibm.com/infocenter/idshelp/v111/index.jsp?topic=/com.ibm.dbext.doc/dbext270.htm
-- Christoph
/Per