Skip to content

Instantly share code, notes, and snippets.

@appcoreopc
Last active March 25, 2016 05:31
Show Gist options
  • Save appcoreopc/8a4e3d79cc528042e77a to your computer and use it in GitHub Desktop.
Save appcoreopc/8a4e3d79cc528042e77a to your computer and use it in GitHub Desktop.
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