Skip to content

Instantly share code, notes, and snippets.

@c4urself
Created October 5, 2012 17:18
Show Gist options
  • Save c4urself/3841110 to your computer and use it in GitHub Desktop.
Save c4urself/3841110 to your computer and use it in GitHub Desktop.
Prototyping example
function Engineer () {}
Engineer.prototype = {
getYearsWorked: function () {
return this.yearsWorked;
}
};
function UIEngineer (years) {
this.yearsWorked = years;
}
UIEngineer.prototype = new Engineer();
var x = new UIEngineer(5)
x.getYearsWorked();
//>>> 5
if (x instanceof Engineer) console.log("Is Engineer!");
//>>> Is Engineer!
if (x instanceof UIEngineer) console.log("Is UI Engineer!");
//>>> Is UI Engineer!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment