Skip to content

Instantly share code, notes, and snippets.

@bentesha
Created August 13, 2018 16:22
Show Gist options
  • Save bentesha/75875158a6443461e61a410dc35d8143 to your computer and use it in GitHub Desktop.
Save bentesha/75875158a6443461e61a410dc35d8143 to your computer and use it in GitHub Desktop.
const introduce = function() {
console.log("Hi! I'm " + this.name + ". My job is " + this.job + ".");
}
function makeRobot(name, job) {
return {
name: name,
job: job,
introduce,
_isRobotInstance: true
};
}
var bender = makeRobot("Bender", "bending");
bender.introduce(); // Hi! I'm Bender. My job is bending.
if(bender._isRobotInstance){
console.log("Bender is a Robot");
}
var wallE = makeRobot("Wall-E", "trash collection");
wallE.introduce(); // Hi! I'm Wall-E. My job is trash collection.
if(wallE._isRobotInstance){
console.log("wallE is a Robot");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment