0% found this document useful (0 votes)
24 views

Web Programming

The document discusses three methods of creating objects in JavaScript - using object literals, creating new instances, and using object constructors. It demonstrates each method by creating sample objects and outputting their properties to the DOM.

Uploaded by

Hemesh R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Web Programming

The document discusses three methods of creating objects in JavaScript - using object literals, creating new instances, and using object constructors. It demonstrates each method by creating sample objects and outputting their properties to the DOM.

Uploaded by

Hemesh R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Web programming

NAME: R HEMESH REG NO. 22BCT0328


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body><br><br>
<div id="c"></div><br><br>
<div id="b"></div><br><br>
<div id="a"></div>
<script>
obj={name:"Hemesh",id:328,code:"1/3",context:"1st method -By creating
object literal"}

document.getElementById("c").innerHTML+=("CONTEXT:"+obj.context+"<br>NAME:"+o
bj.name+"<br>ID:"+obj.id+"<br>completion of work: "+obj.code)

var obj2= new Object();


obj2.context="2nd method -By creating new instance of the object"
obj2.co="2/3"

document.getElementById("b").innerHTML+=("CONTEXT:"+obj2.context+"<br>"+"comp
letion of work:"+obj2.co)

function job(name,id,salary,work){
this.name=name;
this.id=id;
this.salary=salary;
this.work=work;}
obj3= new job("Hemesh",000111,25000,"3RD METHOD-This is created using
object constructor")
document.getElementById("a").innerHTML+=obj3.work+"<br>"

document.getElementById("a").innerHTML+="Name:"+obj3.name+"<br>ID:"+obj3.id+"
<br>SALARY:"+obj3.salary
</script>
</body>
</html>

You might also like