Created
May 30, 2018 11:00
-
-
Save khg0712/5fc5216cf23f7444991070b8ed4e98b9 to your computer and use it in GitHub Desktop.
프로토타입 객체 메서드와 this 바인딩
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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