September 2019
Beginner
512 pages
12h 52m
English
In the same way that Dart functions are nothing more than objects, Dart classes can behave like functions too, that is, they can be invoked, take some arguments, and return something as a result. The syntax for emulating a function in a class is as follows:
class ShouldWriteAProgram { // this is simple class String language; String platform; ShouldWriteAProgram(this.language, this.platform); // this special method named 'call' makes the class behave as a function bool call(String category) { if(language == "Dart" && platform == "Flutter") { return category != "to-do"; } return false; } }main() { var shouldWrite = ShouldWriteAProgram("Dart", "Flutter"); print(shouldWrite("todo")); // prints false. // this function is invoking ...Read now
Unlock full access