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) 编辑
 
摘要: //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 阅读全文
posted @ 2020-01-16 18:55 bobo2404 阅读(311) 评论(0) 推荐(0) 编辑
 
摘要: 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 阅读全文
posted @ 2020-01-16 18:05 bobo2404 阅读(93) 评论(0) 推荐(0) 编辑
 
摘要: 作用域分为4种: 一.全局作用域window:函数外部定义的变量 注:1.var abc=123; 是全局变量,不能删除delete abc结果为false abcd=2345 没有用var定义的变量是作为window的属性使用,可以删除 delete abcd || delete window.a 阅读全文
posted @ 2020-01-16 17:46 bobo2404 阅读(306) 评论(0) 推荐(0) 编辑