How to use the object in JavaScript? [Resolved]

Posted by Programmer123 under JavaScript on 9/24/2013 | Points: 10 | Views : 1149 | Status : [Member] | Replies : 4
How to use the object in JavaScript? Can any tell me?




Responses

Posted by: Murugavelmsc on: 9/25/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
http://www.w3schools.com/js/js_objects.asp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/25/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
An object is just a container for a collection of named values:

var man = new Object();
man.name = 'Vikas Ahlawat';
man.living = true;
man.age = 27;


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 9/25/2013 [Member] Starter | Points: 25

Up
0
Down
hi,
refer this links it might be helpful to you
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/25/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Sample: Creating the Employee Object
<script>
/*
Employee
--------
Fields:
Id
Name

EmployeeCollection
-------------------
Fields:
indexer
count
Functions:
Add
Delete
Display
*/


//This Function is used to create the collection object.
//Copy this function to create your own collection objects.
function CreateCollection(ClassName)
{
var obj=new Array();
eval("var t=new "+ClassName+"()");
for(_item in t)
{
eval("obj."+_item+"=t."+_item);
}
return obj;
}

function EmployeeCollection()
{
this.Container="";
this.Add=function(obj)
{
this.push(obj);
}
this.Display=function()
{
str="<Table border=1 width=200 ><tr><td>" +
"<b>Name</b></td><td><b>" +
"Age</b></td><tr>";
for(i=0;i<this.length;i++)
str+="<Tr><Td>"+this[i].Name+
"</Td><Td>"+this[i].Age+
"</Td></Tr>";
str+="</Table>";
this.Container.innerHTML=str;
}
}

function Employee(Name,Age)
{
this.Name=Name;
this.Age=Age;
}

//Using the EmployeeCollection and Employee Obejcts
empCollection=new CreateCollection("EmployeeCollection");
empCollection.Add(new Employee("Jax",26));
empCollection.Add(new Employee("Shionk",45));
empCollection.Add(new Employee("Maya",25));
empCollection.Container=document.getElementById("grid");
alert(empCollection[0].Name);
empCollection.Display();

</script>


Reference:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
http://www.codeproject.com/Articles/13357/Using-Objects-In-JavaScript

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response