This commit is contained in:
Ilya Kantor 2017-03-28 10:55:51 +03:00
parent e76364de01
commit bc9117e70f
10 changed files with 15 additions and 15 deletions

View file

@ -46,7 +46,7 @@ For example, here `1+2` results in `3`, and `hello("debugger")` returns nothing,
## Breakpoints
Let's examine what's going on within the code. In `hello.js`, click at the line number `4`. Yes, right on the `"4"` digit, not on the code.
Let's examine what's going on within the code of the [example page](debugging/index.html). In `hello.js`, click at the line number `4`. Yes, right on the `"4"` digit, not on the code.
Contratulations! You've set a breakpoint. Please also click on the number for line `8`.

View file

@ -157,7 +157,7 @@ let user = {
let admin = user;
user = null; // overwrite to make things obvious
admin.sayHi(); // wops! inside sayHi(), the old name is used! error!
admin.sayHi(); // Woops! inside sayHi(), the old name is used! error!
```
If we used `this.name` instead of `user.name` inside the `alert`, then the code would work.

View file

@ -287,7 +287,7 @@ let obj = {};
weakMap.set(obj, "ok"); // works fine (object key)
*!*
weakMap.set("test", "wops"); // Error, because "test" is a primitive
weakMap.set("test", "Woops"); // Error, because "test" is a primitive
*/!*
```

View file

@ -23,7 +23,7 @@ alert(user); // {name: "John", age: 30}
...But in the process of development, new properties are added, old properties are renamed and removed. Updating such `toString` every time can become a pain. We could try to loop over properties in it, but what is the object is complex and has nested objects in properties? We'd need to implement their conversion as well. And, if we're sending the object over a network, then we also need to supply the code to "read" our object on the receiving side.
Luckily, there's no need to write the code to handle all this. The task has been solved already.
Luckily, there's no need to write the code to handle all this. The task has been solved already.
[cut]
@ -31,7 +31,7 @@ Luckily, there's no need to write the code to handle all this. The task has been
The [JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a general format to represent values and objects. It is described as in [RFC 4627](http://tools.ietf.org/html/rfc4627) standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever.
JavaScript provides methods:
JavaScript provides methods:
- `JSON.stringify` to convert objects into JSON.
- `JSON.parse` to convert JSON back into an object.
@ -477,7 +477,7 @@ alert( meetup.date.getDate() ); // Error!
*/!*
```
Wops! An error!
Woops! An error!
The value of `meetup.date` is a string, not a `Date` object. How `JSON.parse` may know that it should transform that string into a `Date`?

View file

@ -8,7 +8,7 @@ JavaScript gives exceptional flexibility when dealing with functions. They can b
Let's say we have a function `slow(x)` which is CPU-heavy, but its results are stable. In other words, for the same `x` it always returns the same result.
If the function is called often, we may want to cache (remember) the results for different `x` to evade spending extra-time on recalculations.
If the function is called often, we may want to cache (remember) the results for different `x` to evade spending extra-time on recalculations.
But instead of adding that functionality into `slow()` we'll create a wrapper. As we'll see, there are many benefits of doing so.
@ -106,7 +106,7 @@ alert( worker.slow(1) ); // the original method works
worker.slow = cachingDecorator(worker.slow); // now make it caching
*!*
alert( worker.slow(2) ); // WOPS! Error: Cannot read property 'someMethod' of undefined
alert( worker.slow(2) ); // WOOPS! Error: Cannot read property 'someMethod' of undefined
*/!*
```
@ -241,7 +241,7 @@ There are many solutions possible:
1. Implement a new (or use a third-party) map-like data structure that is more versatile and allows multi-keys.
2. Use nested maps: `cache.set(min)` will be a `Map` that stores the pair `(max, result)`. So we can get `result` as `cache.get(min).get(max)`.
3. Join two values into one. In our particular case we can just use a string `"min,max"` as the `Map` key. For flexibility, we can allow to provide a *hashing function* for the decorator, that knows how to make a one value from many.
3. Join two values into one. In our particular case we can just use a string `"min,max"` as the `Map` key. For flexibility, we can allow to provide a *hashing function* for the decorator, that knows how to make a one value from many.
For many practical applications, the 3rd variant is good enough, so we'll stick to it.

View file

@ -154,7 +154,7 @@ The `super` in the arrow function is the same as in `stop()`, so it works as int
```js
// Unexpected super
setTimeout(function() { super.stop() }, 1000);
setTimeout(function() { super.stop() }, 1000);
```
````
@ -210,7 +210,7 @@ let rabbit = new Rabbit("White Rabbit", 10); // Error: this is not defined.
*/!*
```
Wops! We've got an error. Now we can't create rabbits. What went wrong?
Woops! We've got an error. Now we can't create rabbits. What went wrong?
The short answer is: constructors in inheriting classes must call `super(...)`, and (!) do it before using `this`.

View file

@ -612,7 +612,7 @@ For instance:
*/!*
function readData() {
badFunc(); // wops, something went wrong!
badFunc(); // Woops, something went wrong!
}
readData();

View file

@ -47,13 +47,13 @@ class ValidationError extends Error {
}
function test() {
throw new ValidationError("Wops!");
throw new ValidationError("Woops!");
}
try {
test();
} catch(err) {
alert(err.message); // Wops!
alert(err.message); // Woops!
alert(err.name); // ValidationError
alert(err.stack); // a list of nested calls with line numbers for each
}