On Jan 24, 7:55 am, Robin Luscombe <[EMAIL PROTECTED]> wrote:
> 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?
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
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino