forked from yygmind/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
### JS数组常考算法详解 | ||
### JS数组常用算法详解 | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
### JS相关 | ||
|
||
|
||
|
||
#### 介绍Promise,以及优缺点? | ||
|
||
ES6中原生实现了Promise对象,通过状态传递异步操作的消息。Promise对象有三种状态:**pending(进行中)、fulfilled(已完成)、rejected(已失败)**,根据异步操作的结果决定处于何种状态。一旦状态改变就不可再变,状态改变仅有两种pending=>rejected、pending=>resolved。 | ||
|
||
优点:避免了层层嵌套的回调函数,并提供了统一的接口,使异步操作更加容易。 | ||
|
||
缺点:无法取消Promise;如果不设置回调函数,内部错误无法反映到外部。 | ||
|
||
|
||
|
||
多个异步请求在一起,会发生回调地狱的问题,带来阅读和维护困难。 | ||
|
||
promise 本质上是分离了异步数据获取和业务逻辑,从而让开发人员能专注于一个事物,而不必同时考虑业务和数据。 | ||
|
||
```js | ||
// 第一部分 数据获取和加工阶段 | ||
let getUserName = () => { | ||
return new Promise(function (resolve, reject) { | ||
$.get('xxx.com/getUserName', data => resolve(data)); | ||
}; | ||
} | ||
let getMobile = userName => { | ||
return new Promise(function (resolve, reject) { | ||
$.get('xxx.com/getUserMobile?user=' + userName, data => resolve(data)); | ||
}); | ||
} | ||
|
||
// 第二部分 业务逻辑部分 | ||
getUserName().then(userName => { | ||
return getMobile(userName); | ||
}).then(mobile => { | ||
console.log(mobile); | ||
}); | ||
``` | ||
#### 使用Promise 写一个Ajax处理过程 | ||
```js | ||
let http = { | ||
get: url => { | ||
let promise = new Promise((resolve, reject) => { | ||
$.ajax({ | ||
url: url, | ||
method: 'get', | ||
success: data => resolve(data), | ||
error: (xhr, statusText) => reject(statusText) | ||
}); | ||
}); | ||
return promise; | ||
} | ||
}; | ||
|
||
http.get('/login').then(data => { | ||
return data; | ||
}, err => { | ||
return Promise.reject('Sorry, file not Found.'); | ||
}).then(data => { | ||
document.write(data); | ||
}, err => { | ||
document.write(err); | ||
}); | ||
``` | ||
#### Async和callback的区别 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
### 网络和安全相关 | ||
|
||
|
||
|
||
#### 介绍五层因特网协议栈 | ||
|
||
| | 协议 | 描述 | | ||
| :----: | :--------: | ------------------------------------------------------------ | | ||
| 第五层 | 应用层 | 支持网络应用,应用协议仅仅是网络应用的一个组成部分,运行在不同主机上的进程则使用应用层协议进行通信。主要的协议有:http、ftp、telnet、smtp、pop3等。 | | ||
| 第四层 | 传输层 | 负责为信源和信宿提供应用程序进程间的数据传输服务,这一层上主要定义了两个传输协议,传输控制协议即TCP和用户数据报协议UDP。 | | ||
| 第三层 | 网络层 | 负责将数据报独立地从信源发送到信宿,主要解决路由选择、拥塞控制和网络互联等问题。 | | ||
| 第二层 | 数据链路层 | 负责将IP数据报封装成合适在物理网络上传输的帧格式并传输,或将从物理网络接收到的帧解封,取出IP数据报交给网络层。 | | ||
| 第一层 | 物理层 | 负责将比特流在结点间传输,即负责物理传输。该层的协议既与链路有关也与传输介质有关。 | | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters