摘要:
//es5 let Animal = function(type){ this.type = type } Animal.prototype.eat = function (){ console.log('eat food') } let dog = new Animal('dog') let mo 阅读全文
2020年1月16日
摘要:
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 阅读全文
摘要:
//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 阅读全文
摘要:
伪数组:不能调用数组的方法, 1.对象是按索引方式存储数据的 2.它具备length属性 {0:'a',1:'b',length:2} //es5伪数组转换成数组 let args = [].slice.call(arguments) //collection let imgs = [].call( 阅读全文
摘要:
//for of let arr = [1,2,3,4,5] for(let item of arr){ console.log(item) } es6新增加的for of方法不仅可以遍历数组和对象,还可以遍历自定义的数据结构 场景:到超市向老板要最便宜的香肠,打火机,啤酒等,老板肯定要从存货里算下 阅读全文
摘要:
//for循环 const arr = [1,2,3,4,5] for(let i = 0; i < arr.length; i++){ if(arr[i] 2){ //break //continue } } //forEach arr.forEach(function (item){ conso 阅读全文
摘要:
1.let定义的变量具有全局作用域 2.let声明的变量不能用全局对象的属性访问 3.let不能重复定义一个变量 4.let声明的变量不能进行变量提升 { let a = 1 console.log(a) } console.log(a) //报错a未定义 var b = 3 let c = 4 c 阅读全文