Skip to content

Instantly share code, notes, and snippets.

@christopherscott
Created February 11, 2013 22:09
Show Gist options
  • Save christopherscott/4758075 to your computer and use it in GitHub Desktop.
Save christopherscott/4758075 to your computer and use it in GitHub Desktop.
Prototypical inheritance in JavaScript
var Person = {
init: function (name) {
this.name = name;
},
speak: function () {
console.log(this.name);
}
};
var Employee = Object.create(Person);
Employee.work = function () {
console.log(this.name + ' is working');
};
var b = Object.create(Employee);
b.init('chris');
b.speak();
b.work();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment