* Fixed usage of for-in loop in iterator example.

* Fixed typos.
This commit is contained in:
Gagan Rai 2019-02-27 19:46:04 +05:45 committed by Dumitru
parent 563f4f6831
commit bc404ec6f8

View file

@ -1032,7 +1032,7 @@ function* fibonacci(): IterableIterator<number> {
function print(n: number) {
let i = 0;
for (const fib in fibonacci()) {
for (const fib of fibonacci()) {
if (i++ === n) break;
console.log(fib);
}
@ -1070,7 +1070,7 @@ itiriri(fibonacci())
### Use getters and setters
TypeScript supports getter/setter syntax.
Using getters and setters to access data from objects that encapsulate behavior could be better that simply looking for a property on an object.
Using getters and setters to access data from objects that encapsulate behavior could be better than simply looking for a property on an object.
"Why?" you might ask. Well, here's a list of reasons:
- When you want to do more beyond getting an object property, you don't have to look up and change every accessor in your codebase.
@ -1686,7 +1686,7 @@ class HttpRequester {
This is a scary term for a very simple concept. It's formally defined as "If S is a subtype of T, then objects of type T may be replaced with objects of type S (i.e., objects of type S may substitute objects of type T) without altering any of the desirable properties of that program (correctness, task performed, etc.)." That's an even scarier definition.
The best explanation for this is if you have a parent class and a child class, then the base class and child class can be used interchangeably without getting incorrect results. This might still be confusing, so let's take a look at the classic Square-Rectangle example. Mathematically, a square is a rectangle, but if you model it using the "is-a" relationship via inheritance, you quickly get into trouble.
The best explanation for this is if you have a parent class and a child class, then the parent class and child class can be used interchangeably without getting incorrect results. This might still be confusing, so let's take a look at the classic Square-Rectangle example. Mathematically, a square is a rectangle, but if you model it using the "is-a" relationship via inheritance, you quickly get into trouble.
**Bad:**