You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8353525
Browse filesBrowse the repository at this point in the historyBrowse files
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`.
71
+
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`.
72
72
73
73
For instance, here a property `name` is created with all falsy flags:
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`.
99
+
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`.
100
100
101
101
Now let's see effects of the flags by example.
102
102
@@ -209,7 +209,7 @@ Math.PI = 3; // Error
209
209
// delete Math.PI won't work either
210
210
```
211
211
212
-
Making a property non-configurable is one-way road. We cannot change it back, because `defineProperty` doesn't work on non-configurable properties.
212
+
Making a property non-configurable is a one-way road. We cannot change it back, because `defineProperty` doesn't work on non-configurable properties.
213
213
214
214
Here we are making `user.name` a "forever sealed" constant:
215
215
@@ -266,7 +266,7 @@ So, we can set many properties at once.
266
266
267
267
To get many descriptors at once, we can use the method [Object.getOwnPropertyDescriptors(obj)](mdn:js/Object/getOwnPropertyDescriptors).
268
268
269
-
Together with `Object.defineProperties` it can be used as an "flags-aware" way of cloning an object:
269
+
Together with `Object.defineProperties` it can be used as a "flags-aware" way of cloning an object:
270
270
271
271
```js
272
272
let clone =Object.defineProperties({}, Object.getOwnPropertyDescriptors(obj));
Copy file name to clipboardExpand all lines: 1-js/07-object-oriented-programming/02-property-accessors/article.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ alert(user.fullName); // John Smith
55
55
*/!*
56
56
```
57
57
58
-
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.
58
+
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.
59
59
60
60
As of now, `fullName` has only a getter. If we attempt to assign `user.fullName=`, there will be an error.
61
61
@@ -97,7 +97,7 @@ Sometimes it's normal that there's only a setter or only a getter. But the prope
97
97
98
98
## Accessor descriptors
99
99
100
-
Descriptors for accessor properties are different.
100
+
Descriptors for accessor properties are different - as compared with data properties.
101
101
102
102
For accessor properties, there is no `value` and `writable`, but instead there are `get` and `set` functions.
103
103
@@ -182,7 +182,7 @@ Technically, the external code may still access the name directly by using `user
182
182
183
183
## Using for compatibility
184
184
185
-
One of great ideas behind getters and setters -- they allow to take control over a "normal" data property and tweak it at any moment.
185
+
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.
186
186
187
187
For instance, we started implementing user objects using data properties `name` and `age`:
Copy file name to clipboardExpand all lines: 1-js/07-object-oriented-programming/03-prototype-inheritance/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -159,7 +159,7 @@ rabbit.walk = function() {
159
159
rabbit.walk(); // Rabbit! Bounce-bounce!
160
160
```
161
161
162
-
Since now, `rabbit.walk()` call finds the method immediately in the object and executes it, without using the prototype:
162
+
From now on, `rabbit.walk()` call finds the method immediately in the object and executes it, without using the prototype:
163
163
164
164

165
165
@@ -192,7 +192,7 @@ alert(admin.fullName); // John Smith (*)
192
192
admin.fullName="Alice Cooper"; // (**)
193
193
```
194
194
195
-
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.
195
+
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.
Copy file name to clipboardExpand all lines: 1-js/07-object-oriented-programming/04-function-prototype/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ As we know already, `new F()` creates a new object. But what we didn't use yet `
14
14
15
15
That property is used by the JavaScript itself to set `[[Prototype]]` for new objects.
16
16
17
-
**When a new object is created with `new F()`, the `[[Prototype]]` of it is set to `F.prototype`.**
17
+
**When a new object is created with `new F()`, the object's `[[Prototype]]` is set to `F.prototype`.**
18
18
19
19
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.
0 commit comments