flushing the typos buffer

This commit is contained in:
Thierry Parmentelat 2017-05-16 14:19:39 +02:00
parent e6a2f98c9d
commit 8353525053
6 changed files with 12 additions and 12 deletions

View file

@ -68,7 +68,7 @@ Object.defineProperty(obj, propertyName, descriptor)
`descriptor` `descriptor`
: Property descriptor to apply. : Property descriptor to apply.
If the property exist, it updates its flags, otherwise, it creates the property with the given value and flags. Please note, that if a flag is not supplied, it is assumed `false`. If the property exists, `defineProperty` updates its flags. Otherwise, it creates the property with the given value and flags; in that case, if a flag is not supplied, it is assumed `false`.
For instance, here a property `name` is created with all falsy flags: For instance, here a property `name` is created with all falsy flags:
@ -96,7 +96,7 @@ alert( JSON.stringify(descriptor, null, 2 ) );
*/ */
``` ```
Compare it with "normally created" user.name above: now all flags are falsy. If that's not what we want then we'd better to set them to `true` in the `descriptor`. Compare it with "normally created" `user.name` above: now all flags are falsy. If that's not what we want then we'd better set them to `true` in `descriptor`.
Now let's see effects of the flags by example. Now let's see effects of the flags by example.
@ -209,7 +209,7 @@ Math.PI = 3; // Error
// delete Math.PI won't work either // delete Math.PI won't work either
``` ```
Making a property non-configurable is one-way road. We cannot change it back, because `defineProperty` doesn't work on non-configurable properties. Making a property non-configurable is a one-way road. We cannot change it back, because `defineProperty` doesn't work on non-configurable properties.
Here we are making `user.name` a "forever sealed" constant: Here we are making `user.name` a "forever sealed" constant:
@ -266,7 +266,7 @@ So, we can set many properties at once.
To get many descriptors at once, we can use the method [Object.getOwnPropertyDescriptors(obj)](mdn:js/Object/getOwnPropertyDescriptors). To get many descriptors at once, we can use the method [Object.getOwnPropertyDescriptors(obj)](mdn:js/Object/getOwnPropertyDescriptors).
Together with `Object.defineProperties` it can be used as an "flags-aware" way of cloning an object: Together with `Object.defineProperties` it can be used as a "flags-aware" way of cloning an object:
```js ```js
let clone = Object.defineProperties({}, Object.getOwnPropertyDescriptors(obj)); let clone = Object.defineProperties({}, Object.getOwnPropertyDescriptors(obj));

View file

@ -55,7 +55,7 @@ alert(user.fullName); // John Smith
*/!* */!*
``` ```
From outside, an accessor property looks like a regular one. That's the idea of accessor properties. We don't call `user.fullName` as a function, we read it normally: the getter runs behind the scenes. From outside, an accessor property looks like a regular one. That's the idea of accessor properties. We don't **call** `user.fullName` as a function, we **read** it normally: the getter runs behind the scenes.
As of now, `fullName` has only a getter. If we attempt to assign `user.fullName=`, there will be an error. As of now, `fullName` has only a getter. If we attempt to assign `user.fullName=`, there will be an error.
@ -97,7 +97,7 @@ Sometimes it's normal that there's only a setter or only a getter. But the prope
## Accessor descriptors ## Accessor descriptors
Descriptors for accessor properties are different. Descriptors for accessor properties are different - as compared with data properties.
For accessor properties, there is no `value` and `writable`, but instead there are `get` and `set` functions. For accessor properties, there is no `value` and `writable`, but instead there are `get` and `set` functions.
@ -182,7 +182,7 @@ Technically, the external code may still access the name directly by using `user
## Using for compatibility ## Using for compatibility
One of great ideas behind getters and setters -- they allow to take control over a "normal" data property and tweak it at any moment. One of the great ideas behind getters and setters -- they allow to take control over a "normal" data property and tweak it at any moment.
For instance, we started implementing user objects using data properties `name` and `age`: For instance, we started implementing user objects using data properties `name` and `age`:

View file

@ -159,7 +159,7 @@ rabbit.walk = function() {
rabbit.walk(); // Rabbit! Bounce-bounce! rabbit.walk(); // Rabbit! Bounce-bounce!
``` ```
Since now, `rabbit.walk()` call finds the method immediately in the object and executes it, without using the prototype: From now on, `rabbit.walk()` call finds the method immediately in the object and executes it, without using the prototype:
![](proto-animal-rabbit-walk-2.png) ![](proto-animal-rabbit-walk-2.png)
@ -192,7 +192,7 @@ alert(admin.fullName); // John Smith (*)
admin.fullName = "Alice Cooper"; // (**) admin.fullName = "Alice Cooper"; // (**)
``` ```
Here in the line `(*)` the property `admin.fullName` has a getter in the prototype `user`, so it is called. And in the line `(**)` the property is has a setter in the prototype, so it is called. Here in the line `(*)` the property `admin.fullName` has a getter in the prototype `user`, so it is called. And in the line `(**)` the property has a setter in the prototype, so it is called.
## The value of "this" ## The value of "this"

View file

@ -14,7 +14,7 @@ As we know already, `new F()` creates a new object. But what we didn't use yet `
That property is used by the JavaScript itself to set `[[Prototype]]` for new objects. That property is used by the JavaScript itself to set `[[Prototype]]` for new objects.
**When a new object is created with `new F()`, the `[[Prototype]]` of it is set to `F.prototype`.** **When a new object is created with `new F()`, the object's `[[Prototype]]` is set to `F.prototype`.**
Please note that `F.prototype` here means a regular property named `"prototype"` on `F`. It sounds something similar to the term "prototype", but here we really mean a regular property with this name. Please note that `F.prototype` here means a regular property named `"prototype"` on `F`. It sounds something similar to the term "prototype", but here we really mean a regular property with this name.

View file

@ -169,7 +169,7 @@ function showArgs() {
} }
``` ```
That's more efficient, because evades creation of an extra array object `[]`. From the other side -- more letters to write it. That's more efficient, because it avoids the creation of an extra array object `[]`. On the other hand, it is longer to write.
## Summary ## Summary

View file

@ -1,7 +1,7 @@
# Methods for prototypes # Methods for prototypes
In this chapter we cover additional methods to work with the prototype. In this chapter we cover additional methods to work with a prototype.
There are also other ways to get/set a prototype, besides those that we already know: There are also other ways to get/set a prototype, besides those that we already know: