Created
December 4, 2015 06:10
-
-
Save carlosvega20/a683e771a38039f5622c to your computer and use it in GitHub Desktop.
prototype chain
This file contains hidden or 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
//Inheritance | |
var Mass = function () {this.material = "rock"; console.log("init Mass")}; | |
var Planet = function (name) {Mass.call(this); this.name = name || "Planet"; console.log("init "+this.name)}; | |
Planet.prototype = Object.create(Mass.prototype); | |
Planet.prototype.constructor = Planet; | |
var earth = new Planet("earth"); | |
// Second Way | |
function Father () {this.type="Human";} | |
function Son (name) {this.name=name;} | |
Son.prototype = new Father(); | |
var carlos = New Son ('carlos'); | |
//console.log(carlos) | |
/* | |
Son {name: "carlos"} | |
name: "carlos" | |
__proto__: Father | |
type: "Human" | |
__proto__: Father | |
constructor: function Father() | |
__proto__: Object | |
*/ | |
//console.log(earth) | |
/* | |
Planet {material: "rock", name: "earth"} | |
material: "rock" | |
name: "earth" | |
__proto__: Planet | |
constructor: (name) | |
__proto__: Mass | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment