fix
This commit is contained in:
parent
1fb7296f72
commit
e37d4ac498
6 changed files with 28 additions and 23 deletions
|
@ -63,7 +63,7 @@ Comments before and after scripts.
|
|||
//--></script>
|
||||
```
|
||||
|
||||
These comments were supposed to hide the code from an old browser that didn't know about a `<script>` tag. But all browsers born in the past 15+ years don't have any issues. It is only mentioned here, because it serves as a sign. If you see that somewhere -- that code is probably really old and not worth looking into.
|
||||
These comments were supposed to hide the code from an old browser that didn't know about a `<script>` tag. But all browsers born in the past 15+ years don't have any issues. We mention it here, because such comments serve as a sign. If you see that somewhere -- that code is probably really old and not worth looking into.
|
||||
|
||||
|
||||
## External scripts
|
||||
|
@ -105,7 +105,7 @@ That saves traffic and makes pages faster.
|
|||
```
|
||||
|
||||
````warn header="If `src` is set, the script content is ignored."
|
||||
A single `<script>` tag may not have both, `src` attribute and the code inside.
|
||||
A single `<script>` tag may not have both `src` attribute and the code inside.
|
||||
|
||||
This won't work:
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
This part of the tutorial aims to cover JavaScript "as is", without environment-specific tweaks.
|
||||
|
||||
But still we use a browser as the demo environment. So we should know at least few user-interface functions.
|
||||
|
||||
In this chapter we'll get familiar with the browser-specific functions `alert`, `prompt` and `confirm`.
|
||||
But still we use a browser as the demo environment. So we should know at least few user-interface functions. In this chapter we'll get familiar with the browser functions `alert`, `prompt` and `confirm`.
|
||||
|
||||
[cut]
|
||||
|
||||
|
|
|
@ -145,9 +145,7 @@ user.name = "Alice"; // Error
|
|||
|
||||
Now let's add a custom `toString` to `user`.
|
||||
|
||||
Normally, a built-in `toString` for objects is non-enumerable, it does not show up in `for..in`. But if we add `toString` of our own, then by default it shows up in `for..in`.
|
||||
|
||||
...But if we don't like it, then we can set `enumerable:false`. Then it won't appear in `for..in` loop, just like the built-in one:
|
||||
Normally, a built-in `toString` for objects is non-enumerable, it does not show up in `for..in`. But if we add `toString` of our own, then by default it shows up in `for..in`, like this:
|
||||
|
||||
```js run
|
||||
let user = {
|
||||
|
@ -159,6 +157,17 @@ let user = {
|
|||
|
||||
// By default, both our properties are listed:
|
||||
for(let key in user) alert(key); // name, toString
|
||||
```
|
||||
|
||||
If we don't like it, then we can set `enumerable:false`. Then it won't appear in `for..in` loop, just like the built-in one:
|
||||
|
||||
```js run
|
||||
let user = {
|
||||
name: "John",
|
||||
toString() {
|
||||
return this.name;
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(user, "toString", {
|
||||
*!*
|
||||
|
@ -167,7 +176,7 @@ Object.defineProperty(user, "toString", {
|
|||
});
|
||||
|
||||
*!*
|
||||
// Now toString disappears:
|
||||
// Now our toString disappears:
|
||||
*/!*
|
||||
for(let key in user) alert(key); // name
|
||||
```
|
||||
|
@ -178,11 +187,9 @@ Non-enumerable properties are also excluded from `Object.keys`:
|
|||
alert(Object.keys(user)); // name
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Non-configurable
|
||||
|
||||
The non-configurable flag (`configurable:false`) is usually set for built-in objects and properties.
|
||||
The non-configurable flag (`configurable:false`) is sometimes preset for built-in objects and properties.
|
||||
|
||||
A non-configurable property can not be deleted or altered with `defineProperty`.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue