Skip to content

Commit e657009

Browse files
committed
Accept Merge Request #44: (translate_en_dx -> master)
Merge Request: Git 翻译 Created By: @13221097537 Accepted By: @13221097537 URL: https://coding.net/u/mart_13221097537/p/Front-End-Interview-Map/git/merge/44
2 parents b847e79 + 1710067 commit e657009

File tree

3 files changed

+284
-69
lines changed

3 files changed

+284
-69
lines changed

Git/git-en.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
This is not for rookie, we'll introduce somthing about more advanced.
2+
## Merge with Rebase
3+
This command shows no difference with the command `merge`.
4+
5+
We usually use `merge` to merge the code from one branch to `master`. like this:
6+
7+
![](https://user-gold-cdn.xitu.io/2018/4/23/162f109db27be054?w=505&h=461&f=png&s=22796)
8+
9+
After using `rebase`, the commits from `decelop` will be moved to the third `commit` of the `master` in order, as follows:
10+
11+
![](https://user-gold-cdn.xitu.io/2018/4/23/162f11cc2cb8b332?w=505&h=563&f=png&s=26514)
12+
13+
Compare with `merge`, the result of `rebase` is very clear with a single flow. But if there is any conflict, you'll be in troule to solving them. You have to solve them one by one , while you only need to solve them one-time if using `merge`.
14+
15+
You should use `rebase` on the local branchs which need be rebased. If you need to `rebase` the `develop` to the `master`, you should do as follows:
16+
17+
```shell
18+
## branch develop
19+
git rebase master
20+
get checkout master
21+
## 用于将 `master` 上的 HEAD 移动到最新的 commit
22+
get merge develop
23+
```
24+
25+
## stash
26+
27+
Use `git stash` to save the current state of the working directory while you want to fix a temporary bug in development, if you don't want to use `commit`.
28+
29+
```shell
30+
git stash
31+
```
32+
This command can record the current state of the working directory, if you want to recover it, you can do like this:
33+
34+
```shell
35+
git stash pop
36+
```
37+
then you'll back to the exactly state before.
38+
39+
## reflog
40+
41+
This command will show you the records of HEAD's trace. If you delete a branch by mistake, you can examine the hashs of HEAD by using `reflog`.
42+
43+
![](https://user-gold-cdn.xitu.io/2018/4/23/162f14df98ce3d83?w=950&h=118&f=png&s=77151)
44+
45+
According to the picture, the last movement of HEAD is just after `merge`, and then the `new` branch was deleted, so we can get the branch back by the following command:
46+
47+
```shell
48+
git checkout 37d9aca
49+
git checkout -b new
50+
```
51+
52+
PS:`reflog` is time-bound, it can only record the state over a period of time.
53+
54+
55+
## Reset
56+
57+
If you want to delete the last commit, you can do like this:
58+
59+
```shell
60+
git reset --hard HEAD^
61+
```
62+
But this command doesn't delete the commit, it just reset the HEAD and the right branch the HEAD directing.

JS/JS-ch.md

+39-43
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ let a = {
113113
// '1,2' + '2,1' = '1,22,1'
114114
```
115115

116-
对于加号需要注意这个表达式 `'a' + + 'b'`
116+
对于加号需要注意这个表达式 `'a' + + 'b'`
117117

118118
```js
119119
'a' + + 'b' // -> "aNaN"
@@ -206,7 +206,7 @@ function Foo() {
206206
Foo.getName = function () {
207207
console.log('1');
208208
};
209-
Foo.prototype.getName = function () {
209+
Foo.prototype.getName = function () {
210210
console.log('2');
211211
};
212212

@@ -432,10 +432,10 @@ function A() {
432432
经典面试题,循环中使用闭包解决 `var` 定义函数的问题
433433

434434
```Js
435-
for ( var i=1; i<=5; i++) {
436-
setTimeout( function timer() {
437-
console.log( i );
438-
}, i*1000 );
435+
for ( var i=1; i<=5; i++) {
436+
setTimeout( function timer() {
437+
console.log( i );
438+
}, i*1000 );
439439
440440
```
441441

@@ -456,10 +456,10 @@ for (var i = 1; i <= 5; i++) {
456456
第二种就是使用 `setTimeout ` 的第三个参数
457457

458458
```js
459-
for ( var i=1; i<=5; i++) {
460-
setTimeout( function timer(j) {
461-
console.log( j );
462-
}, i*1000, i);
459+
for ( var i=1; i<=5; i++) {
460+
setTimeout( function timer(j) {
461+
console.log( j );
462+
}, i*1000, i);
463463
}
464464
```
465465

@@ -468,10 +468,10 @@ for ( var i=1; i<=5; i++) {
468468
第三种就是使用 `let` 定义 `i`
469469

470470
```js
471-
for ( let i=1; i<=5; i++) {
472-
setTimeout( function timer() {
473-
console.log( i );
474-
}, i*1000 );
471+
for ( let i=1; i<=5; i++) {
472+
setTimeout( function timer() {
473+
console.log( i );
474+
}, i*1000 );
475475
}
476476
```
477477

@@ -482,8 +482,8 @@ for ( let i=1; i<=5; i++) {
482482
let i = 0
483483
{
484484
let ii = i
485-
setTimeout( function timer() {
486-
console.log( i );
485+
setTimeout( function timer() {
486+
console.log( i );
487487
}, i*1000 );
488488
}
489489
i++
@@ -576,9 +576,9 @@ console.log(b.jobs.first) // FE
576576
- 不能解决循环引用的对象
577577

578578
```js
579-
let obj = {
579+
let obj = {
580580
a: 1,
581-
b: {
581+
b: {
582582
c: 2,
583583
d: 3,
584584
},
@@ -612,7 +612,7 @@ console.log(b) // {name: "yck"}
612612

613613
但是在通常情况下,复杂数据都是可以序列化的,所以这个函数可以解决大部分问题,并且该函数是内置函数中处理深拷贝性能最快的。当然如果你的数据中含有以上三种情况下,可以使用 [loadash 的深拷贝函数](https://lodash.com/docs#cloneDeep)
614614

615-
如果你所需拷贝的对象含有内置类型并且不包含函数,可以使用 `MessageChannel`
615+
如果你所需拷贝的对象含有内置类型并且不包含函数,可以使用 `MessageChannel`
616616

617617
```js
618618
function structuralClone(obj) {
@@ -655,7 +655,7 @@ import XXX from './b.js'
655655
module.exports = {
656656
a: 1
657657
}
658-
// or
658+
// or
659659
exports.a = 1
660660

661661
// b.js
@@ -667,7 +667,7 @@ module.a // -> log 1
667667

668668
```js
669669
var module = require('./a.js')
670-
module.a
670+
module.a
671671
// 这里其实就是包装了一层立即执行函数,这样就不会污染全局变量了,
672672
// 重要的是 module 这里,module 是 Node 独有的一个变量
673673
module.exports = {
@@ -678,7 +678,7 @@ var module = {
678678
exports: {} // exports 就是个空对象
679679
}
680680
// 这个是为什么 exports 和 module.exports 用法相似的原因
681-
var exports = module.exports
681+
var exports = module.exports
682682
var load = function (module) {
683683
// 导出的东西
684684
var a = 1
@@ -694,7 +694,6 @@ var load = function (module) {
694694
- 前者支持动态导入,也就是 `require(${path}/xx.js)`,后者目前不支持,但是已有提案
695695
- 前者是同步导入,因为用于服务端,文件都在本地,同步导入即使卡住主线程影响也不大。而后者是异步导入,因为用于浏览器,需要下载文件,如果也采用导入会对渲染有很大影响
696696

697-
698697
- 前者在导出时都是值拷贝,就算导出的值变了,导入的值也不会改变,所以如果想更新值,必须重新导入一次。但是后者采用实时绑定的方式,导入导出的值都指向同一个内存地址,所以导入值会跟随导出值变化
699698
- 后者会编译成 `require/exports` 来执行的
700699

@@ -704,15 +703,15 @@ AMD 是由 `RequireJS` 提出的
704703

705704
```js
706705
// AMD
707-
define(['./a', './b'], function(a, b) {
706+
define(['./a', './b'], function(a, b) {
708707
a.do()
709708
b.do()
710-
})
709+
})
711710
define(function(require, exports, module) {
712711
var a = require('./a')
713712
a.doSomething()
714-
var b = require('./b')
715-
b.doSomething()
713+
var b = require('./b')
714+
b.doSomething()
716715
})
717716

718717
```
@@ -725,7 +724,7 @@ define(function(require, exports, module) {
725724
```js
726725
/**
727726
* underscore 防抖函数,返回函数连续调用时,空闲时间必须大于或等于 wait,func 才会执行
728-
*
727+
*
729728
* @param {function} func 回调函数
730729
* @param {number} wait 表示时间窗口的间隔
731730
* @param {boolean} immediate 设置为ture时,是否立即调用函数
@@ -782,7 +781,7 @@ _.debounce = function(func, wait, immediate) {
782781
```js
783782
/**
784783
* underscore 节流函数,返回函数连续调用时,func 执行频率限定为 次 / wait
785-
*
784+
*
786785
* @param {function} func 回调函数
787786
* @param {number} wait 表示时间窗口的间隔
788787
* @param {object} options 如果想忽略开始函数的的调用,传入{leading: false}。
@@ -859,13 +858,13 @@ Super.prototype.getNumber = function() {
859858

860859
function Sub() {}
861860
let s = new Sub()
862-
Sub.prototype = Object.create(Super.prototype, {
863-
constructor: {
864-
value: Sub,
865-
enumerable: false,
866-
writable: true,
867-
configurable: true
868-
}
861+
Sub.prototype = Object.create(Super.prototype, {
862+
constructor: {
863+
value: Sub,
864+
enumerable: false,
865+
writable: true,
866+
configurable: true
867+
}
869868
})
870869
```
871870

@@ -976,7 +975,7 @@ Function.prototype.myApply = function (context) {
976975
977976
`bind` 和其他两个方法作用也是一致的,只是该方法会返回一个函数。并且我们可以通过 `bind` 实现柯里化。
978977
979-
同样的,也来模拟实现下 `bind`
978+
同样的,也来模拟实现下 `bind`
980979
981980
```js
982981
Function.prototype.myBind = function (context) {
@@ -996,7 +995,7 @@ Function.prototype.myBind = function (context) {
996995
}
997996
```
998997
999-
装饰器原理
998+
装饰器原理
1000999
10011000
#### Promise 实现
10021001
@@ -1006,7 +1005,7 @@ Promise 是 ES6 新增的语法,解决了回调地狱的问题。
10061005
10071006
`then` 函数会返回一个 Promise 实例,并且该返回值是一个新的实例而不是之前的实例。因为 Promise 规范规定除了 `pending` 状态,其他状态是不可以改变的,如果返回的是一个相同实例的话,多个 `then` 调用就失去意义了。
10081007
1009-
对于 `then` 来说,本质上可以把它看成是 `flatMap`
1008+
对于 `then` 来说,本质上可以把它看成是 `flatMap`
10101009
10111010
```js
10121011
// 三种状态
@@ -1117,7 +1116,7 @@ MyPromise.prototype.then = function (onResolved, onRejected) {
11171116
}));
11181117
}
11191118
};
1120-
// 规范 2.3
1119+
// 规范 2.3
11211120
function resolutionProcedure(promise2, x, resolve, reject) {
11221121
// 规范 2.3.1,x 不能和 promise2 相同,避免循环引用
11231122
if (promise2 === x) {
@@ -1373,6 +1372,3 @@ let p = onWatch(obj, (v) => {
13731372
p.a = 2 // bind `value` to `2`
13741373
p.a // -> Get 'a' = 2
13751374
```
1376-
1377-
1378-

0 commit comments

Comments
 (0)