Last active
March 25, 2016 05:31
-
-
Save appcoreopc/8a4e3d79cc528042e77a to your computer and use it in GitHub Desktop.
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
var car = function() { | |
this.wheel = true; | |
this.seats = true; | |
} | |
var ferrarri = function() { | |
this.carType = "fast car"; | |
} | |
// inherits | |
ferrarri.prototype = new car(); | |
// whenever we create an instance of ferrarri, the new object will contain car's properties. | |
var jackCar = new ferrarri(); | |
jackCar.wheel; // true; | |
jackCar.seats; // true; | |
// to figure out ferrarri's parent | |
jackCar.__proto__ // car {wheel: true, seats: true} | |
// defining a new method for object | |
ferrarri.prototype.getName = function() { return "ferrari"; } | |
// create new instance | |
var newCar = new ferrarri(); | |
// returns ferrarri // | |
newCar.getName() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment