Skip to content

Instantly share code, notes, and snippets.

@thatkookooguy
Created November 8, 2018 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatkookooguy/a1d0ac1402c95198ca570fe5cfde6f54 to your computer and use it in GitHub Desktop.
Save thatkookooguy/a1d0ac1402c95198ca570fe5cfde6f54 to your computer and use it in GitHub Desktop.
function canEat(obj) {
obj.eat = eat;
obj.energy = 0;
function eat(energy) {
if (!this) { return; }
this.energy = this.energy || 0;
this.energy += energy;
return this.energy;
}
}
class Rabbit {
constructor(name) {
this.name = name;
}
}
let phillip = new Rabbit('phillip');
console.log(phillip.name); // 'phillip'
console.log(phillip.eat); // undefined
phillip.eat = eat;
console.log(phillip.eat) // undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment