Skip to content

Instantly share code, notes, and snippets.

@jeena
Created May 8, 2010 15:48
Show Gist options
  • Save jeena/394620 to your computer and use it in GitHub Desktop.
Save jeena/394620 to your computer and use it in GitHub Desktop.
// Record Object
function Record(id) {
this.id = id;
}
Record.prototype.save = function() {
console.log("saving record " + this.id);
}
Record.prototype.delete = function() {
console.log("deleting record " + this.id);
}
// User Object
function User(id) {
this.constructor(id)
};
// Inheritance
User.prototype = new Record();
// Adding method
User.prototype.test = function() {
console.log("testing user" + this.id);
}
// Overwriting a method
User.prototype.delete = function() {
console.log("deleting user " + this.id);
// Calling a overwritten parent method
Record.prototype.delete.call(this);
}
// Test
var aUser = new User(22);
aUser.save();
aUser.test();
console.log(aUser.id);
aUser.delete();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment