문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
wiki:javascript:javascript_note:js_classes_-_class_intro [2021/04/12 10:06] emblim98 |
wiki:javascript:javascript_note:js_classes_-_class_intro [2023/01/13 18:44] (현재) |
||
---|---|---|---|
줄 121: | 줄 121: | ||
====예제==== | ====예제==== | ||
클래스 메소드에 __매개 변수__(parameters)를 보낼 수 있습니다.\\ | 클래스 메소드에 __매개 변수__(parameters)를 보낼 수 있습니다.\\ | ||
- | < | + | < |
< | < | ||
< | < | ||
줄 141: | 줄 141: | ||
let year = date.getFullYear(); | let year = date.getFullYear(); | ||
let myCar = new Car(" | let myCar = new Car(" | ||
- | document.getElementById(" | + | document.getElementById(" |
</ | </ | ||
</ | </ | ||
</ | </ | ||
</ | </ | ||
+ | |||
+ | =====" | ||
+ | 클래스의 구문은 " | ||
+ | \\ | ||
+ | " | ||
+ | |||
+ | ====예제==== | ||
+ | "stict mode" | ||
+ | <code javascript> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <p>In a JavaScript Class you cannot use variable without declaring it.</ | ||
+ | <p id=" | ||
+ | < | ||
+ | class Car { | ||
+ | constructor(name, | ||
+ | this.name = name; | ||
+ | this.year = year; | ||
+ | } | ||
+ | age() { | ||
+ | // date = new Date(); | ||
+ | let date = new Date(); // This will wrok | ||
+ | return date.getFullYear() - this.year; | ||
+ | } | ||
+ | } | ||
+ | myCar = new Car(" | ||
+ | document.getElementById(" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
{{tag> | {{tag> |