Page 223 - Web_Application_v2.0_C12_Fb
P. 223
Example 30: To demonstrate the use of delete method
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>JavaScript Object Methods Example</TITLE>
</HEAD>
<BODY>
<P> Manage Object Methods</P>
<SCRIPT>
// Creating an object
var student = {
name: "John Doe",
age: 20,
greet: function() {
document.write("Hello, my name is " + this.name + " and I am " + this.age + "
years old.<BR>");
}};
// Adding a new method
student.study = function() {
document.write(this.name + " is studying.<BR>");
};
// Updating an existing method
student.greet = function() {
document.write("Hi, I am " + this.name + " and I am " + this.age + " years old.<BR>");
};
// Calling methods
student.greet();
student.study();
// Deleting a method
delete student.study;
</SCRIPT>
</BODY>
</HTML>
Output:
JavaScript Part 2 221

