Objects are another powerful way of handling and storing of data. In arrays the indexes are commonly numerical; objects give us a better way of assigning and retrieving data.
<html>
<script type="text/javascript">
/* Declare Object*/
var detail = new object();
/* initialize the array */
detail.firstname = 'naveen';
detail.lastname = 'kumar';
detail.email = 'xxx@hotmail.com';
detail.getFullDetail = function(){
alert(detail.firstname+ ' '+ detail.lastname + ' '+ detail.email);
}
detail.getFullDetail();
</script>
</html>
Another way of creating an object is by using the curly braces.
<html>
<script type="text/javascript">
/* Declare Object*/
var detail = {
'firstname':'naveen',
'lastname':'kumar',
'email':'xxx@hotmail.com',
'getFullDetail' = function(){
alert(this.firstname+ ' '+ this.lastname + ' '+ this.email);
}
detail.getFullDetail();
</script>
</html>
Thanks
0 Comment(s)