Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What's Prototypes for JavaScript?
What's Prototypes for JavaScript?
✍: Guest
Objects have "prototypes" from which they may inherit fields and functions.
<script type="text/javascript">
function movieToString() {
return("title: "+this.title+" director: "+this.director);
}
function movie(title, director) {
this.title = title;
this.director = director || "unknown"; //if null assign to "unknown"
this.toString = movieToString; //assign function to this method pointer
}
movie.prototype.isComedy = false; //add a field to the movie's prototype
var officeSpace = new movie("OfficeSpace");
var narnia = new movie("Narni","Andrew Adamson");
document.write(narnia.toString());
document.write("<br />Narnia a comedy? "+narnia.isComedy);
officeSpace.isComedy = true; //override the default just for this object
document.write("<br />Office Space a comedy? "+officeSpace.isComedy);
</script>
2011-08-23, 4086👍, 0💬
Popular Posts:
Where are all .NET Collection classes located ? System.Collection namespace has all the collection c...
How do we get the current culture of the environment in windows and ASP.NET? “CultureInfo.CurrentCul. ..
What Articles Have You Read about JUnit? There are a number of JUnit articles that you should read: ...
What Happens If a Hyper Link Points to a Music File? - XHTML 1.0 Tutorials - Understanding Hyper Lin...
How Many Tags Are Defined in HTML 4.01? There are 77 tags defined in HTML 4.01: a abbr acronym addre...