摘要: // 解决异步回调地狱的方案: async + promise async function writeFile() { // 打开文件 const fd = await new Promise((resolve, reject) => { // 执行 打开文件 异步操作 fs.open('c.tx 阅读全文
posted @ 2019-12-14 10:57 詹姆斯小皇帝 阅读(224) 评论(0) 推荐(0) 编辑
摘要: move(); function move() { // 动画最流畅,性能最好 window.requestAnimationFrame(function () { // 这个函数会在下一次重排重绘之前调用(将当前函数操作dom导致的重排重绘和下一次重排重绘合并成一次) // 执行动画 x++; b 阅读全文
posted @ 2019-12-14 10:56 詹姆斯小皇帝 阅读(247) 评论(0) 推荐(0) 编辑
摘要: /* 自定义promise 1. 执行MyPromise构造函数,要立即执行executor 2. promise实例对象,内部有三种状态 初始化 pending 成功 resolved 失败 rejected 注意:状态只能修改一次 如果executor内部出错了,promise状态改成rejec 阅读全文
posted @ 2019-12-14 10:54 詹姆斯小皇帝 阅读(592) 评论(0) 推荐(0) 编辑
摘要: //防抖函数 function debounce (fn, delay) { let timer = null; return function () { //接收this,该this当前指向dom元素 const that = this; //接收参数 const args = arguments 阅读全文
posted @ 2019-12-14 10:02 詹姆斯小皇帝 阅读(163) 评论(0) 推荐(0) 编辑
摘要: //定义函数 获取对象的构造函数(类)名 function getObjectClass(obj) { return Object.prototype.toString.call(obj).slice(8, -1) } function deepClone(obj) { if (getObjectC 阅读全文
posted @ 2019-12-14 09:59 詹姆斯小皇帝 阅读(172) 评论(0) 推荐(0) 编辑
摘要: const fs = require('fs'); const promise = new Promise((resolve, reject) => { fs.open('./c.txt', 'w', (err, fd) => { if (!err) { resolve(fd); }else { r 阅读全文
posted @ 2019-12-14 09:57 詹姆斯小皇帝 阅读(446) 评论(0) 推荐(0) 编辑
摘要: Function.prototype.call2 = function (context, ...args) { var context = context || window; //改变this指向 context.__proto__.fn = this; //调用函数 var res = con 阅读全文
posted @ 2019-12-14 09:55 詹姆斯小皇帝 阅读(532) 评论(0) 推荐(0) 编辑