Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,994
    Thanks
    120
    Thanked 76 Times in 76 Posts

    has no properties - complicated

    on main web page

    Code:
    <script language="javascript" src="../js/BadBoy.js" type="text/javascript">
    </script>

    BadBoy.js basicaly contains this:
    Code:
    function B() 
    { 
    }
    
    function A(obj,method,parameters)
    {   
       B.obj = obj;
       B.method = method; 
       B.parameters = parameters;
    }

    1.now, if I put button on main page and on click --> A ..
    it works.
    2. if I dynamicaly fill one div on main page via ajax with exact same code as in 1. then I get :B has no properties

    Obviously it gets into A, and code is there, so this is not scope problem, or is it ?

    Thanks for reply.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    well B is not an Object...

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    how can you call B.obj , I rather think that bs should be this.obj etc...

  • #4
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,994
    Thanks
    120
    Thanked 76 Times in 76 Posts
    I made it an object, same thing.

    Code:
    function B() 
    { 
       this.obj = null;
       this.method = null;
       this.parameters = null;
    };
    
    b= new B(); 
    
    function A(obj,method,parameters)
    { 
       alert(b); in first case I get [object Object], in secod null
       b.obj = obj;
       b.method = method; 
       b.parameters = parameters;
    }
    1.now, if I put button on main page and on click --> A ..
    it works.
    2. if I dynamicaly fill one div on main page via ajax with exact same code as in 1. then I get :B has no properties
    note allso : if I click second option first, then clicking first does not work any more, allso returns null.

    ?
    Last edited by BubikolRamios; 01-01-2008 at 07:50 PM.

  • #5
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,994
    Thanks
    120
    Thanked 76 Times in 76 Posts
    changed it like this, works.
    Have no idea what is happennig coz this generaly worked so far.

    Code:
    function B() 
    { 
       this.obj = null;
       this.method = null;
       this.parameters = null;
    };
    
    //b= new B(); 
    
    function A(obj,method,parameters)
    { 
       b= new B(); 
       alert(b); 
       b.obj = obj;
       b.method = method; 
       b.parameters = parameters;
    }

  • #6
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    It is working because you declared the object inside of the funciton as a global variable. hence you have a variable b that contains an object that you can store values in.

    Read this from my book: http://java.sun.com/javascript/ajaxi...ction_ApB.html

    Might help you understand OO JavaScript a little better.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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