Skip to content

Instantly share code, notes, and snippets.

@khg0712
Created May 30, 2018 11:00
Show Gist options
  • Save khg0712/5fc5216cf23f7444991070b8ed4e98b9 to your computer and use it in GitHub Desktop.
Save khg0712/5fc5216cf23f7444991070b8ed4e98b9 to your computer and use it in GitHub Desktop.
프로토타입 객체 메서드와 this 바인딩
function Animal(species) {
this.species = species;
}
var frog = new Animal('frog');
frog.getSpecies();//Error
Animal.prototype.getSpecies = function() {
console.log(this.species);
};
frog.getSpecies();//frog 출력
Animal.prototype.getSpecies();//undefined 출력
Animal.prototype.species = 'animal';
Animal.prototype.getSpecies();//animal 출력
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment