- 博客(7)
- 收藏
- 关注
原创 promise polyfill
promise polyfillv1.0 CustomePromise构造器定义,状态从pending变为fulfilled/rejected,并且不可逆;(function(){ // 定义三种状态 const status = { pending: 0, /*进行时*/ fulfilled: 1, /*成功*/ rejecte...
2018-11-09 15:33:57
1867
原创 promise介绍
promise使用new Promise返回的对象称之为Promise对象三种状态: pending 正在进行 fulfilled 已完成 rejected 已失败1. new Promise 接收一个函数 executor2. 函数 executor 接收两个参数,resolve,reject 调用resolve的时候,把promise对象转成成功状态...
2018-11-09 15:28:40
282
原创 deep clone
deep clonefunction clone(obj){ let vv = null if( typeof obj == 'object' && obj !== null ){ vv = obj instanceof Array ? [] : {} for( let v in obj ){ vv[v] ...
2018-11-06 18:14:00
125
原创 函数防抖debounce/函数节流throttle
函数防抖debounce函数节流throttle函数防抖:将几次操作合并为一此操作进行。原理是维护一个计时器,规定在delay时间后触发函数,但是在delay时间内再次触发的话,就会取消之前的计时器而重新设置。这样一来,只有最后一次操作能被触发函数节流:使得一定时间内只触发一次函数。原理是通过判断是否到达一定时间来触发函数var timeout = nullfunction deboun...
2018-11-06 16:55:26
449
原创 ajax封装
function ajax(method, url, data, success){ /*1.创建一个ajax对象 ie6以下new ActiveXObject('Microsoft.XMLHTTP')*/ var xhr; if( window.XMLHttpRequest ){ xhr = new XMLHttpReque...
2018-11-06 10:14:26
128
原创 es5class
基本类function Person(){ // 属性 this.name = 'zhangsan' this.age = 20 // 实例方法 this.run = () => { console.log( this.name + '在运动' ) }}let p = new Person()console.log(p...
2018-11-06 10:07:09
426
原创 bind polyfill
bind usefunc.bind(thisArg[, arg1[, arg2[, …]]])thisArg改变目标函数this指向的值,若为基本类型将转化为基本类型对应的包装对象// bind使用function func(...arg){ console.log(this) console.log(arg)}let newFunc = func.bind([1,2...
2018-11-06 10:06:24
441
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人