Skip to content

Instantly share code, notes, and snippets.

@michaelBenin
Created May 25, 2012 16:42
Show Gist options
  • Save michaelBenin/2789120 to your computer and use it in GitHub Desktop.
Save michaelBenin/2789120 to your computer and use it in GitHub Desktop.
nyman
*/
function Being () {
this.living = true;
}
Being.prototype.breathes = function () {
return true;
};
Robert.prototype = new Being;
function Robert () {
this.blogs = true;
}
Robert.prototype.getsBored = function () {
return alert("You betcha");
};
// Create an instance of the Robert object
var me = new Robert();
/*
Returns "You betcha" as it's a method
belonging to the Robert object
*/
me.getsBored();
/*
Returns true. Since the Robert object
doesn't have a breathes method of
its own, it goes back in the
prototype chain to its parent
object, Being, and finds the
method there
*/
me.breathes();
Robert.prototype.getsBored = function () {
/*
Basically, you need to know the name of
the object and the method name as well.
Then call it in context
*/
Being.prototype.getsBored.call(this);
//return alert("You betcha");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment