Page MenuHomePhabricator (Chris)

example-object-prototype-override.html
No OneTemporary

Authored By
Unknown
Size
898 B
Referenced Files
None
Subscribers
None

example-object-prototype-override.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<h1>JavaScript Example </h1>
<br>
Creating objects using prototypes.
For one instance, a method defined in the prototype is overridden.
<br>
<hr>
<br>
<!-- SCRIPT STARTS HERE -->
<script type="text/javascript">
function Person(firstName,name) {
this.firstName = firstName;
this.name = name;
}
Person.prototype.fullName = function () {
return this.firstName + " " + this.name;
};
var person1 = new Person("Jens","Dietrich");
var person2 = new Person("Giovanni","Moretti");
// now override fullName defined in the prototype for a single instance
person2.fullName = function () {
return this.firstName + " " + this.name + "*";
};
document.write(person1.fullName());
document.write("<p>");
document.write(person2.fullName());
</script>
</body>
</html>

File Metadata

Mime Type
text/html
Expires
Sat, Nov 14, 4:38 PM (9 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
134889
Default Alt Text
example-object-prototype-override.html (898 B)

Event Timeline