Method (method)
Để implement method trong class của JavaScript, sử dụng cú pháp method.
jsclassGreeter {greet (name ) {return `Hello, ${name }!`;}}
jsclassGreeter {greet (name ) {return `Hello, ${name }!`;}}
Type annotation cho method
Trong TypeScript, có thể type annotation cho tham số và giá trị trả về của method.
tsclassGreeter {greet (name : string): string {return `Hello, ${name }!`;}}
tsclassGreeter {greet (name : string): string {return `Hello, ${name }!`;}}
Type annotation cho method giống với type annotation cho function declaration. Có thể bỏ qua type annotation cho tham số và giá trị trả về. Về hành vi trong trường hợp đó, tham khảo function declaration.
📄️ Function declaration
Function declaration là cú pháp để định nghĩa function trong JavaScript.