摘要:
//map实例化,存入的数据格式是二维数组 let map = new Map() //添加 map.set(1,2) map.set(3,'value-3') //删除,通过key删除 map.delete(1) //清空 map.clear() //获取长度 map.size //判断是否存在对 阅读全文
2020年1月17日
摘要:
set:无序的不重复的value的集合体 //实例化容器 let s = new Set()//方法一 let s = new Set([1,2,3,4])//方法二,里面存储可循环的数据,不一定是数组,对象,只要是可循环的都可以 //添加数据 //s.add('hello') //s.add('g 阅读全文
摘要:
function sum (x = 1, y = 2, z = 3) { return x + y + z } let data = [4,5,9] console.log(sum(data[0],data[1],data[2])) console.log(sum.apply(this,data)) 阅读全文
摘要:
场景:求出不定参数的总数和 //利用arguments function sum () { let num = 0 //Array.prototype.forEach.call(arguments,function (item){ //num += item * 1 //}) Array.from( 阅读全文
摘要:
//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) 阅读全文
摘要:
//es5其中的一种继承方法 let Animal = function (type){ this.type = type } //这是类的实例对象方法 Animal.prototype.eat = function (){ Animal.walk()//引用类的静态方法 console.log(' 阅读全文
摘要:
//es5 let Animal = function (type){ this.type = type } //这是类的实例对象方法 Animal.prototype.eat = function (){ Animal.walk()//引用类的静态方法 console.log('eat food' 阅读全文
摘要:
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 阅读全文