Skip to content

Commit 8da945a

Browse files
author
YuChengKai
committed
校对
1 parent 98902e4 commit 8da945a

File tree

1 file changed

+59
-60
lines changed

1 file changed

+59
-60
lines changed

JS/JS-en.md

+59-60
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
- [Comparison Operator](#comparison-operator)
1313
- [New](#new)
1414
- [This](#this)
15-
- [instanceof](#instanceof)
16-
- [scope](#scope)
15+
- [Instanceof](#instanceof)
16+
- [Scope](#scope)
1717
- [Closure](#closure)
1818
- [Prototypes](#prototypes)
19-
- [inheritance](#inheritance)
19+
- [Inheritance](#inheritance)
2020
- [Deep and Shallow Copy](#deep-and-shallow-copy)
21-
- [shallow copy](#shallow-copy)
22-
- [deep copy](#deep-copy)
23-
- [the differences between call, apply, bind](#the-differences-between-call-apply-bind)
21+
- [Shallow copy](#shallow-copy)
22+
- [Deep copy](#deep-copy)
23+
- [The differences between call, apply, bind](#the-differences-between-call-apply-bind)
2424
- [simulation to implement `call` and `apply`](#simulation-to-implement---call-and--apply)
2525
- [Promise implementation](#promise-implementation)
2626
- [Throttle](#throttle)
2727
- [Map、FlapMap and Reduce](#mapflapmap-and-reduce)
28-
- [async and await](#async-and-await)
28+
- [Async and await](#async-and-await)
2929
- [Proxy](#proxy)
3030
- [Why 0.1 + 0.2 != 0.3](#why-01--02--03)
3131
- [Regular Expressions](#regular-expressions)
@@ -35,7 +35,7 @@
3535

3636
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3737

38-
#### Built-in Types
38+
# Built-in Types
3939
JavaScript defines seven built-in types, which can be broken down into two categories: `Primitive Type` and `Object`.
4040

4141
There are six primitive types: `null` , `undefined` , `boolean` , `number` , `string` , `symbol `.
@@ -63,7 +63,7 @@ console.log(a) // EF
6363
```
6464

6565

66-
#### Typeof
66+
# Typeof
6767

6868
`typeof` can always display the correct type of the primitive types, except `null`
6969
```js
@@ -103,27 +103,27 @@ let undefined = 1
103103
a === void 0
104104
```
105105

106-
#### Type Conversion
106+
# Type Conversion
107107

108-
##### Converting to Boolean
108+
## Converting to Boolean
109109

110-
Other than `undefined``null``false``NaN``''``0``-0`, all of the values, including objects, are converted to `true`.
110+
Except `undefined``null``false``NaN``''``0``-0`, all of the values, including objects, are converted to `true`.
111111

112-
##### Objects to Primitive Types
112+
## Objects to Primitive Types
113113

114114
When objects are converted, `valueOf` and `toString` will be called, respectively in order. These two methods can also be overridden.
115115

116116
```js
117117
let a = {
118118
valueOf() {
119-
return 0
119+
return 0
120120
}
121121
}
122122
```
123123

124-
##### Arithmetic Operators
124+
## Arithmetic Operators
125125

126-
Only for additions, if one of the parameters is a string, the other will be converted to string as well. For all other operations, as long as one of the parameters is a number, the other will be converted to a number.
126+
Only for additions, if one of the parameters is a string, the other will be converted to the string as well. For all other operations, as long as one of the parameters is a number, the other will be converted to a number.
127127

128128
Additions will invoke three types of type conversions: to primitive types, to numbers, and to string.
129129

@@ -144,13 +144,13 @@ Note the expression `'a' + + 'b'` for addition.
144144
// You might have seen + '1' -> 1
145145
```
146146

147-
##### `==` operator
147+
## `==` operator
148148

149-
![](https://user-gold-cdn.xitu.io/2018/3/30/16275f89ebf931e9)
149+
![](https://user-gold-cdn.xitu.io/2018/3/30/16275cb21f5b19d7?w=1630&h=1208&f=png&s=496784)
150150

151151
`toPrimitive` in the above figure is converting objects to primitive types.
152152

153-
`===` is usually recommeded to compare to values. However, if you would like to know if a value is `null`, you can use `xx == null`.
153+
`===` is usually recommended to compare to values. However, if you would like to know if a value is `null`, you can use `xx == null`.
154154

155155
Let's take a look at an example `[] == ![] // -> true`. The following explains why the expression evaluates to `true`.
156156

@@ -168,13 +168,12 @@ ToPrimitive([]) == 0
168168
0 == 0 // -> true
169169
```
170170

171-
##### Comparison Operator
171+
## Comparison Operator
172172

173173
1. If it's an object, `toPrimitive` is used.
174174
2. If it's a string, `unicode` character index is used to compare.
175-
3.
176175

177-
#### New
176+
# New
178177

179178
1. Create a new object
180179
2. Chained to prototype
@@ -240,7 +239,7 @@ new (Foo.getName());
240239
For the first function, `Foo.getName()` is executed first, so the result is 1;
241240
As for the latter, it firstly executes `new Foo()` to create an instance, then finds the `getName` function on `Foo` via the prototype chain, so the result is 2.
242241

243-
#### This
242+
# This
244243

245244
`This`, a concept that many people will confuse, is not difficult to understand, as long as you remember the following rules
246245

@@ -285,7 +284,7 @@ console.log(a()()());
285284
Actually , the arrow function does not have `this` , `this` in the above function only depends on the first function outside that is not arrow function . In above case , `this` is default to `window` because calling `a` matches the first situation in the above codes . And , what `this` is bound to will not be changed by any code once `this` is bound to the context
286285

287286

288-
#### instanceof
287+
# Instanceof
289288

290289
The `instanceof` operator can correctly judge the type of the object , bacause it’s internal mechanism is to find out if `prototype` of this type can be found in the prototype chain of the object
291290
let’s try to implement it
@@ -306,7 +305,7 @@ function instanceof(left, right) {
306305
}
307306
```
308307

309-
#### scope
308+
# Scope
310309

311310
Executing JS code would generate execution environment , as long as the code is not written in a function , it belongs to the global execution environment . The code in a function will generate function execution environments , but only two (there’s an `eval`, which basically will not be used, so you can think of only two execution environments))
312311

@@ -345,7 +344,7 @@ var b = 'Hello world'
345344

346345
Using `var` is more likely to make mistake , thus ES6 introduces a new keyword `let` . `let` has an important feature that it can’t be used before declared , which mismatches the often saying that `let` doesn’t have the ability of hoisting . Indeed, `let` hoists declared , but does not assign a value, because the temporary dead zone.
347346

348-
#### Closure
347+
# Closure
349348

350349
The definition of a closure is simple: Function A returns a function B, and function B uses a variable of function A, and the function B is called a closure.
351350

@@ -429,7 +428,7 @@ For `let`, it will create a block-level scope, which is equivalent to:
429428
}
430429
```
431430

432-
#### Prototypes
431+
# Prototypes
433432

434433
![](https://camo.githubusercontent.com/71cab2efcf6fb8401a2f0ef49443dd94bffc1373/68747470733a2f2f757365722d676f6c642d63646e2e786974752e696f2f323031382f332f31332f313632316538613962636230383732643f773d34383826683d35393026663d706e6726733d313531373232)
435434

@@ -440,7 +439,7 @@ Each object has an internal property, denoted as `__proto__` , which is a refere
440439
Objects can use `__proto__` to find properties that do not belong to the object, and `__proto__` connects objects together to form a prototype chain.
441440

442441

443-
#### inheritance
442+
# Inheritance
444443

445444
In ES5, we can solve the problems of inheritance by using the following ways.
446445

@@ -503,7 +502,7 @@ The Implement ideas of the above inheritance: firstly create the instance of par
503502
The inheritance implement with the above method can perfectly solve the restriction on low-level of JS.
504503
505504
506-
#### Deep and Shallow Copy
505+
# Deep and Shallow Copy
507506
508507
```js
509508
let a = {
@@ -518,7 +517,7 @@ From the above example, we can see that if you assign an object to a variable,
518517
519518
Usually, we don't want such problem to appear during development, thus we can use shallow copy to solve this problem.
520519
521-
##### shallow copy
520+
## Shallow copy
522521
523522
Firstly we can solve the problem by `Object.assign`
524523
```js
@@ -554,7 +553,7 @@ console.log(b.jobs.first) // native
554553
```
555554
The shallow copy only solves the problem of the first layer. If the object contains objects, then it returns to the beginning topic that the values of both share the same reference. To solve the problem, we need to introduce deep copy.
556555
557-
##### deep copy
556+
## Deep copy
558557
559558
The problem can usually be solved by `JSON.parse(JSON.stringify(object))`
560559
@@ -628,7 +627,7 @@ var obj = {a: 1, b: {
628627
const clone = await structuralClone(obj);
629628
```
630629
631-
#### the differences between call, apply, bind
630+
# The differences between call, apply, bind
632631
633632
Firstly, let’s tell the difference between the former two.
634633
@@ -649,7 +648,7 @@ getValue.call(a, 'yck', '24')
649648
getValue.apply(a, ['yck', '24'])
650649
```
651650
652-
##### simulation to implement `call` and `apply`
651+
## simulation to implement `call` and `apply`
653652
654653
We can consider how to implement them from the following points
655654
@@ -715,7 +714,7 @@ Function.prototype.myBind = function (context) {
715714
}
716715
```
717716
718-
#### Promise implementation
717+
# Promise implementation
719718
720719
`Promise` is a new syntax introduced by ES6, which resolves the problem of callback hell.
721720
@@ -908,7 +907,7 @@ The above codes, which is implemented based on the Promise / A+ specification,
908907
![](https://user-gold-cdn.xitu.io/2018/3/29/162715e8e37e689d?w=1164&h=636&f=png&s=300285)
909908
910909
911-
#### Throttle
910+
# Throttle
912911
913912
`Debounce` and `Throttle` are different in nature. `Debounce` is to turn multiple executions into the last execution, and `Throttle` is to turn multiple executions into execution at regular intervals.
914913
@@ -971,7 +970,7 @@ _.throttle = function(func, wait, options) {
971970
};
972971
```
973972
974-
#### Map、FlapMap and Reduce
973+
# Map、FlapMap and Reduce
975974
976975
The effect of the `Map` is to generate a new array, iterate over the original array, take each element out to do some transformation, and then `append` to the new array.
977976
@@ -1022,7 +1021,7 @@ function b() {
10221021
```
10231022
10241023
1025-
#### async and await
1024+
# Async and await
10261025
10271026
A function with `async`, then the function will return a `Promise`.
10281027
@@ -1079,13 +1078,13 @@ You may have doubts about the above code, here explain the principle
10791078
- At this point, the synchronization code is executed and asynchronous code is started. The saved value is used. At this time, `a = 10`
10801079
- Then comes the usual code execution
10811080
1082-
#### Proxy
1081+
# Proxy
10831082
10841083
Proxy is a new feature since ES6. It can be used to define operations in objects.
10851084
10861085
```js
10871086
let p = new Proxy(target, handler);
1088-
// `target` represents the object to add the proxy to
1087+
// `target` represents the object of need to add the proxy
10891088
// `handler` customizes operations in the object
10901089
```
10911090
@@ -1117,11 +1116,11 @@ p.a = 2 // bind `value` to `2`
11171116
p.a // -> Get 'a' = 2
11181117
```
11191118
1120-
#### Why 0.1 + 0.2 != 0.3
1119+
# Why 0.1 + 0.2 != 0.3
11211120
1122-
Because JS incorporated IEEE 754 for double float numbers (64 bits). Every language that uses this standard has this problem.
1121+
Because JS uses the IEEE 754 double-precision version (64-bit). Every language that uses this standard has this problem.
11231122
1124-
As you know, computers uses binaries to represent decimals, so `0.1` in binary is represented as
1123+
As we know, computers uses binaries to represent decimals, so `0.1` in binary is represented as
11251124
11261125
```js
11271126
// (0011) represents cycle
@@ -1138,40 +1137,40 @@ Binary computations in float numbers are different from those in integers. For m
11381137
11391138
Back to the double float for IEEE 754 standard. Among the 64 bits, one bit is used for signing, 11 used for integer bits, and the rest 52 bits are floats. Since `0.1` and `0.2` are infinitely cycling binaries, the last bit of the floats needs to indicate whether to round (same as rounding in decimals).
11401139
1141-
After rounding, `2^-4 * 1.10011...001` becomes `2^-4 * 1.10011(0011 * 12)010`. After adding these two binaries we get `2^-2 * 1.0011(0011 * 11)0100`, which is `0.30000000000000004` in decimals.
1140+
After rounding, `2^-4 * 1.10011...001` becomes `2^-4 * 1.10011(0011 * 12 times)010`. After adding these two binaries we get `2^-2 * 1.0011(0011 * 11 times)0100`, which is `0.30000000000000004` in decimals.
11421141
11431142
The native solution to this problem is shown below:
11441143
11451144
```js
11461145
parseFloat((0.1 + 0.2).toFixed(10))
11471146
```
11481147
1149-
#### Regular Expressions
1148+
# Regular Expressions
11501149
1151-
##### Metacharacters
1150+
## Metacharacters
11521151
1153-
| Metacharacter | Effect |
1154-
| :-----------: | :----------------------------------------------------------------------------------------------------------------------: |
1155-
| . | Matches any character other than the new line character |
1156-
| [] | matches anything within the brackets. For example, [0-9] can match any number |
1157-
| ^ | ^9 means matching anything that starts with '9'; [`^`9] means not matching characters other than '9' in between brackets |
1158-
| {1, 2} | matches 1 or 2 digit characters |
1159-
| (yck) | only matches strings the same as 'yck' |
1160-
| \| | matches any character before of after \| |
1161-
| \ | escape character |
1162-
| * | only matches character before '*' appearing -1 times or above |
1163-
| + | only matches character before '+' appearing 0 times or above |
1164-
| ? | the character before '?' is optional |
1152+
| Metacharacter | Effect |
1153+
| :-----------: | :----------------------------------------------------------: |
1154+
| . | Matches any character except the new line character |
1155+
| [] | matches anything within the brackets. For example, [0-9] can match any number |
1156+
| ^ | ^9 means matching anything that starts with '9'; [`^`9] means not matching characters except '9' in between brackets |
1157+
| {1, 2} | matches 1 or 2 digit characters |
1158+
| (yck) | only matches strings the same as 'yck' |
1159+
| \| | matches any character before and after \| |
1160+
| \ | escape character |
1161+
| * | Matches the preceding expression 0 or more times |
1162+
| + | Matches the preceding expression 1 or more times |
1163+
| ? | the character before '?' is optional |
11651164
1166-
##### Flags
1165+
## Flags
11671166
11681167
| Flag | Effect |
11691168
| :------: | :--------------: |
1170-
| i | ignores casing |
1169+
| i | Case-insensitive search |
11711170
| g | matches globally |
11721171
| m | multiline |
11731172
1174-
##### Character Shorthands
1173+
## Character Shorthands
11751174
11761175
| shorthand | Effect |
11771176
| :--: | :------------------------: |

0 commit comments

Comments
 (0)