JAVASCRIPT OBJECT ORIENTED PROGRAMMING
In this post let us see how to create a
javascript function and how to create object the function.
Step 1:
Let us use Notepad++ as our editor, we create
new html page and save with .html extension.
Here is the sample code for the page created for the demo.
Step 2:
<html lang="en">
<head>
<title>:::JAVASCRIPT
OBJECTS:::</title>
</head>
<body>
<script
type="text/javascript">
//javascript function with two parameters, it
is a constructor function
function
showDetails(name, age)
{
this.name
= name;
this.age
= age;
}
//Creating
object for the function showDetails
var
emp = new showDetails("Pradeep", 24);
//Displaying
the name into the browser
document.write("My
name is : <b>" + emp.name +
"</b><br />");
//Displaying
the age into the browser
document.write("My
age is : <b>" + emp.age + "</b><br />");
</script>
</body>
</html>
Finally execute the program in the browser and
see output. Thank you,
Output:
Output:
No comments:
Post a Comment