Skip to content

Instantly share code, notes, and snippets.

@fiveisprime
Created June 17, 2012 01:26
Show Gist options
  • Save fiveisprime/2943077 to your computer and use it in GitHub Desktop.
Save fiveisprime/2943077 to your computer and use it in GitHub Desktop.
Object.create inheritance example
var employee = Object.create(matt, {
id: {
value: '1234',
writable: false
},
credentials: {
get: function() {
return this.introduce() + " and my ID is: " + this.id;
}
}
});
console.log(employee.credentials);
var employee = Object.create(matt);
var employee = Object.create(matt, {
id: {
value: '1234'
},
getCredentials: {
value: function() {
return this.introduce() + " and my ID is: " + this.id;
}
}
});
console.log(employee.getCredentials());
function Person(name) {
this.name = name;
}
Person.prototype.introduce = function() {
return "Hi, I'm " + this.name;
};
var matt = new Person('Matt');
console.log(matt.introduce());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment