[Dart] Dart-02-14: Callable classes
Dart-02: Language Tour | ||
---|---|---|
Dart-02-01 | Important concepts | |
Dart-02-02 | Keywords | |
Dart-02-03 | Variables | |
Dart-02-04 | Built-in types | |
Dart-02-05 | Functions | |
Dart-02-06 | Operators | |
Dart-02-07 | Control flow statements | |
Dart-02-08 | Exceptions | |
Dart-02-09 | Classes | |
Dart-02-10 | Generics | |
Dart-02-11 | Libraries and visibility | |
Dart-02-12 | Asynchrony support | |
Dart-02-13 | Generators | |
Dart-02-14 | Callable classes | |
Dart-02-15 | Isolates | |
Dart-02-16 | Typedefs | |
Dart-02-17 | Metadata | |
Dart-02-18 | Comments |
Callable classes
Dart class의 instance가 함수처럼 호출되도록 하려면, call()
method를 구현한다.
다음 예제에서, WannabeFunction
class는 세 개의 string을 가져와 연결하고, 각각을 공백으로 구분하고, 느낌표를 추가하는 call() 함수를 정의한다.
class WannabeFunction {
String call(String a, String b, String c) => '$a $b $c!';
}
var wf = WannabeFunction();
var out = wf('Hi', 'there', 'gang');
void main() => print(out);
댓글남기기