上一页 1 ··· 4 5 6 7 8 9 10 下一页

2020年1月17日

摘要: 场景:求出不定参数的总数和 //利用arguments function sum () { let num = 0 //Array.prototype.forEach.call(arguments,function (item){ //num += item * 1 //}) Array.from( 阅读全文
posted @ 2020-01-17 17:33 bobo2404 阅读(544) 评论(0) 推荐(0) 编辑
 
摘要: //es5 function f (x,y,z) { if(y undefined){ y = 7 } if(z undefined){ y = 42 } return x + y + z } console.log(f(1,8,43)) //es6 function f1 (x,y=7,z=42) 阅读全文
posted @ 2020-01-17 17:15 bobo2404 阅读(105) 评论(0) 推荐(0) 编辑
 
摘要: //es5其中的一种继承方法 let Animal = function (type){ this.type = type } //这是类的实例对象方法 Animal.prototype.eat = function (){ Animal.walk()//引用类的静态方法 console.log(' 阅读全文
posted @ 2020-01-17 16:19 bobo2404 阅读(104) 评论(0) 推荐(0) 编辑
 
摘要: //es5 let Animal = function (type){ this.type = type } //这是类的实例对象方法 Animal.prototype.eat = function (){ Animal.walk()//引用类的静态方法 console.log('eat food' 阅读全文
posted @ 2020-01-17 11:54 bobo2404 阅读(141) 评论(0) 推荐(0) 编辑
 
摘要: let _age = 4 class Animal { construct (type){ this.type = type } get age(){ return _age } set age(val){ if(val < 7 && val >4){ _age = val } } eat(){ c 阅读全文
posted @ 2020-01-17 11:13 bobo2404 阅读(111) 评论(0) 推荐(0) 编辑

2020年1月16日

摘要: //es5 let Animal = function(type){ this.type = type } Animal.prototype.eat = function (){ console.log('eat food') } let dog = new Animal('dog') let mo 阅读全文
posted @ 2020-01-16 22:40 bobo2404 阅读(400) 评论(0) 推荐(0) 编辑
 
摘要: let array = [1,2,3,4,5] //es5 let find = array.filter(function (item){ return item %2 0//返回满足条件的所有值 }) //es6 let find = array.find(function (item){ re 阅读全文
posted @ 2020-01-16 21:45 bobo2404 阅读(1792) 评论(0) 推荐(0) 编辑
 
摘要: //es5 let array = Array(5) let array = [] //es6 1.let array = Array.of(1,2,3,4,5) 2.let array = Array(5).fill(1) 3.Array.from 阅读全文
posted @ 2020-01-16 21:22 bobo2404 阅读(653) 评论(0) 推荐(0) 编辑
 
摘要: 伪数组:不能调用数组的方法, 1.对象是按索引方式存储数据的 2.它具备length属性 {0:'a',1:'b',length:2} //es5伪数组转换成数组 let args = [].slice.call(arguments) //collection let imgs = [].call( 阅读全文
posted @ 2020-01-16 19:46 bobo2404 阅读(964) 评论(0) 推荐(0) 编辑
 
摘要: //for of let arr = [1,2,3,4,5] for(let item of arr){ console.log(item) } es6新增加的for of方法不仅可以遍历数组和对象,还可以遍历自定义的数据结构 场景:到超市向老板要最便宜的香肠,打火机,啤酒等,老板肯定要从存货里算下 阅读全文
posted @ 2020-01-16 19:15 bobo2404 阅读(1161) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 下一页