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: Javascript oop question From: sam conrad Date: September 29, 2003

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.

Sam

 

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];

                                    j++                                          

                                    break;

                        } }

            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;}

            else

                        {this.childNodes = '';      

                        return false;

                        } }

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

var myDOM = new xmlDOM;                                                      

alert(myDOM.loadxml(data));

alert(myDOM.selectSingleNode("2").text);




Reply
Name: 
Email: 
Subject: 

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