...

View Full Version : has no properties - complicated



BubikolRamios
01-01-2008, 05:11 PM
on main web page



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



BadBoy.js basicaly contains this:


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.

A1ien51
01-01-2008, 05:45 PM
well B is not an Object...

Eric

sybil6
01-01-2008, 06:37 PM
how can you call B.obj , I rather think that bs should be this.obj etc...

BubikolRamios
01-01-2008, 07:43 PM
I made it an object, same thing.




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.

?

BubikolRamios
01-01-2008, 08:50 PM
changed it like this, works.
Have no idea what is happennig coz this generaly worked so far.



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

A1ien51
01-02-2008, 03:28 PM
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/ajaxinaction/Ajax_in_Action_ApB.html

Might help you understand OO JavaScript a little better.

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum