Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions 1-js/07-object-properties/01-property-descriptors/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Object.defineProperty(obj, propertyName, descriptor)
```

`obj`, `propertyName`
: The object and property to work on.
: The object and its property to apply the descriptor.

`descriptor`
: Property descriptor object to apply.
Expand Down Expand Up @@ -116,14 +116,14 @@ Object.defineProperty(user, "name", {
});

*!*
user.name = "Pete"; // Error: Cannot assign to read only property 'name'...
user.name = "Pete"; // Error: Cannot assign to read only property 'name'
*/!*
```

Now no one can change the name of our user, unless they apply their own `defineProperty` to override ours.

```smart header="Errors appear only in strict mode"
In the non-strict mode, no errors occur when writing to non-writable properties and such. But the operation still won't succeed. Flag-violating actions are just silently ignored in non-strict.
In non-strict mode, no errors occur when writing to non-writable properties and such. But the operation still won't succeed. Flag-violating actions are just silently ignored in non-strict.
```

Here's the same example, but the property is created from scratch:
Expand All @@ -140,11 +140,10 @@ Object.defineProperty(user, "name", {
*/!*
});

alert(user.name); // Pete
user.name = "Alice"; // Error
alert(user.name); // John
user.name = "Pete"; // Error
```


## Non-enumerable

Now let's add a custom `toString` to `user`.
Expand Down