
ES6
yimawujiang
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
js平铺数组
平铺数组可以使用ES6的flat方法。但是在微信小程序里面并不支持ES6的flat方法,所以我写了下面这个递归函数let flat=function(arr,n=0){ return arr.reduce((a,b)=>{ if(Object.prototype.toString.call(b)==='[object Array]'&&n--){ ret...原创 2019-03-21 11:19:43 · 2427 阅读 · 1 评论 -
js实现抽象工厂模式
class Circle { constructor() { this.shape = "circle" }}class Rectangle { constructor() { this.shape = "rectangle" }}class ShapeFactory { constructor() {} getShapeInstance(shapeType) { ...原创 2019-03-28 11:46:41 · 479 阅读 · 0 评论 -
js实现工厂模式
class Circle{ constructor(){ this.shape="circle" }}class Rectangle{ constructor(){ this.shape="rectangle" }}class ShapeFactory{ constructor(){ } getShapeInstance(shapeType){ shapeTyp...原创 2019-03-28 11:12:25 · 671 阅读 · 0 评论 -
斐波那契数列
计算斐波那契数列第n项的值//方法一:递归var Fibonacci = function(n) { if(Number.isInteger(n) && n) { return n > 2 ? arguments.callee(n - 1) + arguments.callee(n - 2) : 1 }}console.log(Fibonacci(3), ...原创 2019-03-18 16:36:18 · 122 阅读 · 0 评论 -
微信小程序请求拦截器
const apiHttp = 'https://pdm.chiefchain.cn/'const header = { cookie: 'JSESSIONID=' + wx.getStorageSync('JSESSIONID'), 'content-type': 'application/x-www-form-urlencoded'}function request(url,...原创 2019-03-18 15:27:55 · 6249 阅读 · 1 评论 -
利用Proxy实现函数的链式调用
let pipe = function(value) { let funStack = [] return new Proxy({}, { get: function(target, fnName,receive) { if(fnName === 'do') { return funStack.reduce((val, fn) => fn(val), value) ...原创 2019-03-18 14:52:11 · 531 阅读 · 0 评论 -
js判断一个数组是否为另一个数组的子集
var arr=[1,2,3,null,NaN,undefined,Infinity,'']var brr=[0,1,2,3,4,null,NaN,undefined,Infinity,'']if(!Array.prototype.subsetTo){ Array.prototype.subsetTo=function(arr){ return this.every(v=>arr...原创 2019-03-21 18:19:06 · 6734 阅读 · 0 评论 -
去重
数组去重在ES6可以通过Set数据结构来实现let arr=[null,null,undefined,undefined,NaN,NaN,Infinity,Infinity,'','',,1,'1']console.log([...new Set(arr)])//[null, undefined, NaN, Infinity, "",1,'1']使用filter方法:let ar...原创 2019-03-21 17:27:52 · 238 阅读 · 0 评论 -
js判斷变量的类型
一:判断数组:console.log(Array.isArray([]))//trueconsole.log([] instanceof Array)//trueconsole.log(Object.prototype.toString.call([])==='[object Array]')//true二:判断函数let fn=()=>{}console.log(fn...原创 2019-03-21 16:22:39 · 113 阅读 · 0 评论 -
用Generator函数实现jQuery的toggle方法
HTMLElement.prototype.toggle = function (...args) { let generator = function* (...args) { let i = 0; do { yield args[i++ % args.length] } while (true) }; ...原创 2019-03-18 10:45:23 · 136 阅读 · 0 评论