Created
July 18, 2021 06:25
-
-
Save CreatiCoding/30982f0cdf265f523cdae4f0c829e54a to your computer and use it in GitHub Desktop.
JS 클래스와 함수
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 Person(name){ this.name = name; } | |
| Person.prototype.say = function(){ console.log(this.name); } | |
| var creco = new Person("creco") | |
| creco.say() | |
| class Person2 { | |
| constructor(name) { | |
| this.name = name; | |
| } | |
| say() { | |
| console.log(this.name); | |
| } | |
| } | |
| var creco2 = new Person2("creco2"); | |
| creco2.say() | |
| // 자바스크립트의 클래스 본질은 함수다. | |
| // this는 호출된 곳의 주인을 가리킨다. |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
클래스와 함수의 차이