Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F619347
example-object-prototype-override.html
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
898 B
Referenced Files
None
Subscribers
None
example-object-prototype-override.html
View Options
<!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
Details
Attached
Mime Type
text/html
Expires
Sat, Nov 14, 4:38 PM (10 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
134889
Default Alt Text
example-object-prototype-override.html (898 B)
Attached To
Mode
R21 OOP Examples
Attached
Detach File
Event Timeline