Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript object type conversion

Status
Not open for further replies.

sumon2

Programmer
Sep 5, 2002
5
GB
Hi all,
I am trying to store object(user defined) into array and then display it when required.

eg:
function E(fieldname,msg)
{
// initialize the member variables for this instance
this.x= fieldname;
this.y= msg;

// initialize the member function references
this.getFieldname = getFieldname;
this.setFieldname = setFieldname;
this.getmsg = getmsg;
this.setmsg = setmsg;
}


function getFieldname()
{
return this.fieldname;
}

function setFieldname(fieldname)
{
this.fieldname = fieldname;
}
function getmsg()
{
return this.msg;
}

function setmsg(msg)
{
this.msg = msg;
}
//end
Then storing these in array
later on iterate the array and get to the object variables.But it does not understand the object.
In java the objects could be typecasted don't know in javaScript?
something like this
var c=(E)object;
Is it posssible?
Does any one know?
Thanks in advance.

 
Javascript is basically typeless, so typecasting isn't part of the language. Give a real example of what you want to do, not one you make up just for your question, and we can answer you then.

To do what you showed, you'd use:

var c=new E(fieldname, msg);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top