Skip to content

Instantly share code, notes, and snippets.

@bentesha
Forked from sevperez/constructor.js
Last active August 13, 2018 16:09
Show Gist options
  • Save bentesha/a0bebb6577fdf8d65116baa504e59472 to your computer and use it in GitHub Desktop.
Save bentesha/a0bebb6577fdf8d65116baa504e59472 to your computer and use it in GitHub Desktop.
function Robot(name, job) {
this.name = name;
this.job = job;
}
Robot.prototype.introduce = function() {
console.log("Hi! I'm " + this.name + ". My job is " + this.job + ".");
};
var bender = new Robot("Bender", "bending");
bender.introduce(); // Hi! I'm Bender. My job is bending.
console.log(bender instanceof Robot); // true
var wallE = new Robot("Wall-E", "trash collection");
wallE.introduce(); // Hi! I'm Wall-E. My job is trash collection.
console.log(wallE instanceof Robot); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment