October 2017
Intermediate to advanced
280 pages
6h 50m
English
In the beginning of the section on using static typing, we mentioned the type parameters. In order to get a better understanding of them, let's begin with an example. Let's suppose that we want to implement the classical data structure BinarySearchTree. Let's define its interface using a class without applying any method implementations:
class Node {
value: any;
left: Node;
right: Node;
}
class BinarySearchTree {
private root: Node;
insert(any: value): void { /* ... */ }
remove(any: value): void { /* ... */ }
exists(any: value): boolean { /* ... */ }
inorder(callback: {(value: any): void}): void { /* ... */ }
}
In the preceding snippet, we defined a class called Node. The instances of this class ...
Read now
Unlock full access