Created
May 25, 2012 16:42
-
-
Save michaelBenin/2789120 to your computer and use it in GitHub Desktop.
nyman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*/ | |
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