SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question About OO Javascript and "this"

    Got a simple question maybe someone an assist me in figuring it out. I'm using the below code to better under my understanding of javascript objects.

    What reason is there for me getting this error message "this.SomeTxt is not a function"

    Code:
    var MyNewObj = new Test('random string');
    MyNewObj.prntTxt();
    
    function Test(Txt) {
    
    		this.Txt = 'No string specified';
    
    		this.prntTxt= function() {
    				document.onmousedown = this.Func1;
    			}
    
    		this.Func1= function(e) {
                                    if(e==null) {
    						e = window.event;
    					}
    				if(e.target!=null) {
    						var MyElem = e.target;
    					} else {
    						var MyElem = e.srcElement;
    					}
                                    if(MyElem.style.className = 'PrntNow')
    				       this.SomeTxt('test');
                            }
    
                    this.SomeTxt = function(MyTxt) {
    		 		document.write(MyTxt);
    			}
          }
    PHP MySQL Shopping Cart
    www.eprocart.com

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To answer your question, I recommend that you read these:
    Objectifying JavaScript
    Scope in JavaScript
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •