Re: Can you prototype the XML literal exposed in E4X?
Martin Honnen <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Organization | Liberty Development |
| Message-ID | <[email protected]> |
Lucky wrote:
> var xml = <sample/>;
>
> can i prototype the resultant document?
E4X does not know documents, it has XML objects and XMLList objects (and
even does a lot to prevent you from distinguishing those). XML objects
then can have different node kind, element, comment, processing
instruction, attribute.
In your sample above xml is simply an XML object for which
xml.nodeKind() gives 'element'. It is
xml instanceof XML
however.
E4X as currently specified is a bit broken when it comes to prototype
inheritance and the ability to add methods for instance as you can do
with other native objects. But Brendan has introduced a special
namespace named function in Spidermonkey, the JavaScript engine in
Mozilla, and that way you could do e.g.
var xml = <sample/>;
XML.prototype.function::praise = function () {
alert('Kibology for all!\r\n' + this.toXMLString());
};
xml.praise()
in Firefox 1.5/Mozilla 1.8.
--
Martin Honnen
http://JavaScript.FAQTs.com/