Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to extend the XML object?

22 views
Skip to first unread message

Robin Luscombe

unread,
Jan 24, 2008, 7:55:32 AM1/24/08
to dev-tech-js-...@lists.mozilla.org
Hello,

I am interested in defining a function that is available to all XML
objects. I tried the following:

XML.prototype.foo = function() {
// ...
}
var x = <a/>;
x.foo();

However, this results in the following error:

TypeError: Cannot find function foo.

Is it possible to extend XML objects in this way?


Thanks,
Robin

David P. Caldwell

unread,
Jan 24, 2008, 2:45:30 PM1/24/08
to

It is not currently possible to extends XML objects in any way,
really. The problem is that the XML prototype object is itself an XML
object (of type 'text') and hence assigning a property to it like this
is not allowed (or, more properly, does nothing -- see section 9.1.1.2
of the E4X specification, 2nd edition, available at
http://www.ecma-international.org/publications/standards/Ecma-357.htm).

If it -were- in the future to be possible to extend XML objects in
this way, we'd need an extension, like the special ::function
namespace in Spidermonkey, in order to operate on the prototype and
add methods to that. The ::function namespace is not currently
implemented in Rhino.

-- David P. Caldwell
http://www.inonit.com/

>
> Thanks,
> Robin

0 new messages