1. #1
    Ext User digitalkaoz's Avatar
    Join Date
    Jun 2007
    Location
    Rostock, Germany
    Posts
    72
    Vote Rating
    0
    digitalkaoz is on a distinguished road

      0  

    Question how to access instantianted object correctly?

    how to access instantianted object correctly?


    i have some problem in getting instantiated objects.

    here is my code shorthand
    PHP Code:
    //create Jame and Jame.widgets

    Jame.widgets.Message = function(_title){ //message object
        
    this.title _title;
            
    alert(test.title);    //doesnt work, and i dont know why
    }
    Jame.widgets.Login = function(_title){ //login object
        
    this.title _title;
    }

    test = new Jame.widgets.Login("test"); //instantiate login first
    test2= new Jame.widgets.Message("dsfs"); //instantiate message 
    in the Message Object i cant access the instantiated "test" Object (login), what am i doing wrong?
    i would be thankful for any hints...

    greetz digitalkaoz

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    "test" does not exist. You mean "this". You can't, in a constructor, refer to any old variable name that might or might not exist!

    I mean why not write

    Code:
        alert(fooBarBletchVariableName.title);
    It stands just as good a chance of existing!

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Take a look at this thread: http://extjs.com/forum/showthread.php?t=441

  4. #4
    Ext User digitalkaoz's Avatar
    Join Date
    Jun 2007
    Location
    Rostock, Germany
    Posts
    72
    Vote Rating
    0
    digitalkaoz is on a distinguished road

      0  

    Default


    ok but what if there are existing more then 1 MessageWidget? how do i access and/or store them correctly, so i can access there attributes at any time?

    mh ok the objects are needing a return{} function? the public interface?

  5. #5
    Ext User
    Join Date
    Jun 2007
    Posts
    111
    Vote Rating
    0
    Eric Suen is on a distinguished road

      0  

    Default


    Hmm, it works on my computer, both IE and firefox...
    Spket IDE - Development Tool for RIA

  6. #6
    Ext User
    Join Date
    May 2007
    Posts
    106
    Vote Rating
    0
    liggett78 is on a distinguished road

      0  

    Default


    Quote Originally Posted by digitalkaoz View Post
    ok but what if there are existing more then 1 MessageWidget? how do i access and/or store them correctly, so i can access there attributes at any time?

    mh ok the objects are needing a return{} function? the public interface?
    You just add methods to the prototype, like Message.prototype.someFunction = function()... and use this inside the function to refer to the current instance with all data specific to it.

  7. #7
    Ext User digitalkaoz's Avatar
    Join Date
    Jun 2007
    Location
    Rostock, Germany
    Posts
    72
    Vote Rating
    0
    digitalkaoz is on a distinguished road

      0  

    Default


    Quote Originally Posted by liggett78 View Post
    You just add methods to the prototype, like Message.prototype.someFunction = function()... and use this inside the function to refer to the current instance with all data specific to it.
    worked for me thanks...

    http://phrogz.net/JS/Classes/OOPinJS.html maked it a bit clearer to me