WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Javascript oop question, sam conrad, September 29, 2003
     Re:Javascript oop question, Brian R. James, September 29, 2003
         Re:Javascript oop question, Brian R. James, September 29, 2003
             Thanks!!, sam, September 29, 2003

Subject: Re:Javascript oop question From: Brian R. James Date: September 29, 2003

The text and xml properties should be moved out of the xmlDOM class and into a new class definition (ie. xmlNode).  Then the return type of the selectSingleNode method would be an xmlNode object (with the text and xml properties).

Brian R. James

From: sam conrad
Sent: September 29, 2003
Subject: Re:Javascript oop question

Hello!! I’m trying to mimic in Javascript oop, something similar to an XPath-like statement: myDOM.selectSingleNode(“something”).text


Bascially, I want to code a.b(“c”).d

Where  a is an object containing a data array (like an XML DOM, for example, [“aaa”, “bbb”, “ccc”,…])

            b is a method of “a” which gets passed a search argument           

            c is the argument of that search

and       d is the result of that search…


actually, if it is possible in JS to code this kind of “property filter”, I should be able to return additional properties, like a.b(“ccc”).xml = “<x>ccc</x>” and a.b(“ccc”).length = 3, etc…


My problem is getting any value for d (it keeps returning as undefined). I guess there is a scope problem somewhere, but I am puzzled over how to straighten this out. Any suggestions would be greatly appreciated.



Oh, here is my faulty code:

function xmlDOM () {

            this.childNodes = new Array(); 

            this.loadxml = loadxml;                         

            this.length = 0;                            

            this.text = "";                                          

            this.xml = "";                

            this.selectSingleNode = selectSingleNode; }       

function selectSingleNode(_parms){

            var j = 0                          

            for (var i=0;i<this.childNodes.length;i++)

            {if (this.childNodes[i] == _parms)

                        {           this.text = this.childNodes[i];

                                    this.xml = this.childNodes[i];



                        } }

            alert(this.text) // it found it ok here...

            this.length = this.text.length;

            return this.text }

function loadxml(p){

            if (p){     this.childNodes = p;      

                        return true;}


                        {this.childNodes = '';      

                        return false;

                        } }

var data = ["1", "2", "3"];

var myDOM = new xmlDOM;                                                      




Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.

View All Messages
Back to WebFX