Can you prototype the XML literal exposed in E4X?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Can you prototype the XML literal exposed in E4X?

Lucky-3
var xml = <sample/>;

can i prototype the resultant document?

XMLDocument.prototype.blah = ...

will not work, and i thought that i read somewhere it will not get such
a implementation?
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: Can you prototype the XML literal exposed in E4X?

Martin Honnen-3
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/
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: Can you prototype the XML literal exposed in E4X?

Lucky-3
Martin Honnen wrote:

> 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.
>
wow, very nice to know, thanks for the help martin.
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml