Monday, June 29, 2015

What's Prototypes for JavaScript?



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("
Narnia a comedy? "+narnia.isComedy);
officeSpace.isComedy = true; //override the default just for this object
document.write("
Office Space a comedy? "+officeSpace.isComedy);
</script>

2 comments:

  1. http://advancedjavascriptinterview.blogspot.in/2015/06/how-tp-create-arrays-using-javascript.html

    ReplyDelete
  2. http://astutejs.blogspot.in/2015/07/extjs-simple-extjs-grid.html

    ReplyDelete

What is restrict option in directive?

The restrict option in angular directive, is used to specify how a directive will be invoked in your angular app i.e. as an attribute, class...