**簡易Promise:**簡易`Promise`并不完全符合`Promise/A+`規范,但面試時能寫出簡易`Promise`算是已經過關了。
```
function MyPromise(fn) {
let _this = this _this.state = 'pending'_this.value = null _this.reson = null _this.onFulfilledCallbacks = [] _this.onRejectedCallbacks = []
function resolve(value) {
if (_this.state === 'pending') {
_this.value = value _this.state = 'fulled'
_this.onFulfilledCallbacks.map(fn = >fn())
}
}
function reject(reson) {
if (_this.state === 'pending') {
_this.reson = reson _this.state = 'rejected'
_this.onRejectedCallbacks.map(fn = >fn())
}
}
fn(resolve, reject)
}
MyPromise.prototype.then = function(suc, err) {
let _this = this
if (_this.state === 'pending') {
_this.onFulfilledCallbacks.push(() = >{
suc(_this.value);
});
_this.onRejectedCallbacks.push(() = >{
err(_this.value);
})
}
if (_this.state === 'fulled') {
suc(_this.value)
}
if (_this.state === 'rejected') {
err(_this.reson)
}
}
let p = new MyPromise(function(resolve, reject) {
setTimeout(() = >{
resolve('oj8k')
},
1000)
}) p.then(suc = >{
console.log(suc)
},
err = >{
console.log(err)
});
```
- 前言
- 工作中的一些記錄
- 破解快手直播間的webSocket的連接
- 快手「反」反爬蟲的研究記錄
- HTML AND CSS
- 遇到的一些還行的css筆試題
- css常見面試題
- JavaScript 深度剖析
- ES6到ESNext新特性
- 關于http與緩存
- 關于頁面性能
- 關于瀏覽器的重排(reflow、layout)與重繪
- 手寫函數節流
- 手寫promise
- 手寫函數防抖
- 手寫圖片懶加載
- 手寫jsonp
- 手寫深拷貝
- 手寫new
- 數據結構和算法
- 前言
- 時間復雜度
- 棧
- 隊列
- 集合
- 字典
- 鏈表
- 樹
- 圖
- 堆
- 排序
- 搜索
- Webpack
- Webpack原理與實踐
- Vue
- Vuejs的Virtual Dom的源碼實現
- minVue
- Vuex實現原理
- 一道關于diff算法的面試題
- Vue2源碼筆記:源碼目錄設計
- vue-router源碼分析(v4.x)
- React及周邊
- 深入理解redux(一步步實現一個 redux)
- React常見面試題匯總
- Taro、小程序等
- TypeScript
- CI/CD
- docker踩坑筆記
- jenkins
- 最后