Skip to content

Commit

Permalink
新增JS和react相关
Browse files Browse the repository at this point in the history
  • Loading branch information
yygmind committed Aug 22, 2018
1 parent ad04436 commit 1577219
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 8 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### JS数组常考算法详解
### JS数组常用算法详解



Expand Down
77 changes: 77 additions & 0 deletions articles/JS相关.md
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的区别
8 changes: 2 additions & 6 deletions articles/JavaScript常用六种继承方案.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@



[TOC]



#### 1、原型链方案
#### 1、原型链继承

构造函数、原型和实例之间的关系:每个构造函数都有一个原型对象,原型对象都包含一个指向构造函数的指针,而实例都包含一个原型对象的指针。

Expand Down Expand Up @@ -58,7 +54,7 @@ alert(instance2.colors); //"red,blue,green,black"



#### 2、借用构造函数方案
#### 2、借用构造函数继承

使用父类的构造函数来增强子类**实例**,等同于复制父类的实例给子类(不使用原型)

Expand Down
2 changes: 2 additions & 0 deletions articles/React相关.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@



因为 `await` 是异步操作,遇到`await`就会立即返回一个`pending`状态的`Promise`对象,暂时返回执行代码的控制权,使得函数外的代码得以继续执行,所以会先执行 `console.log('1', a)`

18 changes: 18 additions & 0 deletions articles/网络和安全相关.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### 网络和安全相关



#### 介绍五层因特网协议栈

| | 协议 | 描述 |
| :----: | :--------: | ------------------------------------------------------------ |
| 第五层 | 应用层 | 支持网络应用,应用协议仅仅是网络应用的一个组成部分,运行在不同主机上的进程则使用应用层协议进行通信。主要的协议有:http、ftp、telnet、smtp、pop3等。 |
| 第四层 | 传输层 | 负责为信源和信宿提供应用程序进程间的数据传输服务,这一层上主要定义了两个传输协议,传输控制协议即TCP和用户数据报协议UDP。 |
| 第三层 | 网络层 | 负责将数据报独立地从信源发送到信宿,主要解决路由选择、拥塞控制和网络互联等问题。 |
| 第二层 | 数据链路层 | 负责将IP数据报封装成合适在物理网络上传输的帧格式并传输,或将从物理网络接收到的帧解封,取出IP数据报交给网络层。 |
| 第一层 | 物理层 | 负责将比特流在结点间传输,即负责物理传输。该层的协议既与链路有关也与传输介质有关。 |





2 changes: 1 addition & 1 deletion articles/面试题整理.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* [x] 定位问题(绝对定位、相对定位等)
* 从输入URL到页面加载全过程
* tcp3次握手
* tcp属于哪一层(第四层 传输层)
* tcp属于哪一层(1 物理层 -> 2 数据链路层 -> 3 网络层(ip)-> 4 传输层(tcp) -> 5 应用层(http)
* redux的设计思想
* 接入redux的过程
* 绑定connect的过程
Expand Down

0 comments on commit 1577219

Please sign in to comment.