ES6总结

  1. let和const,var
1. 特点:
2.              let有块作用域,不能重复定义,没有变量提升
3.             var没有块作用域,能重复定义,有变量提升

  1. 模板字符串
1. 反引号定义字符串:`  `
2.
3. `  ${  取变量} `  

例如:

1.              let result=`我的姓名是${goods.name},
2.               我的价格是${goods.price}。`

3.对象的解构赋值:

1.对象的解构赋值:var { name1,price1 } = goods;
2.数组的解构赋值:var [one,two]=array1

4.展开操作符和 rest …

展开操作:

列表转数组:… 实参传给 函数形参
数组转列表:….
合并需求:
var arr1=[32,453,546,56]
var arr2=[5,6,78]
arr1=[…arr1,…arr2]

  1. 数组的遍历方法
1.  forEach():即for循环的升级版,返回值是undefined
2.        result=arr1.forEach(function(item,index,arr) {
3.
4.                //遍历
5.
6.        })
7.
8.  filter():即根据条件遍历数组,返回一个新数组
9.  例如:result=arr1.filter(function(item,index,arr) {
10.
11.                 return item>400
12.
13.           })
14.
15.  map():根据遍历结果,返回处理后的数组
16.
17.    例如:
18.    result=users.map(function(item,index){
19.
20.        return `<div>用户名:${item.name},年龄:${item.age}</div>`
21.
22.    })
23.
24.
25.ES6的类和继承
26.
27.   ES5:用函数来模拟类,用prototype来定义公共方法,继承

function Person(name,age) {

1. this.name=name || '用户名';
2. this.age=age || 0;

}

Person.prototype.eat=function() {
console.log(${this.name}会吃饭);
}
function Chinese(name,age) {

1. this.theme="黄色"
2.
3. Person.call(this,name,age);

}

//原型链继承
Chinese.prototype=new Person()

ES5继承参考资料:https://segmentfault.com/a/1190000002440502

1.  call,apply,组合继承,原型链继承
2.
3.   ES6:用class模拟类,用extends实现继承
4.
5.    function  Person(name,age) {
6.
7.         this.name=name || '用户名';
8.         this.age=age || 0;
9.
10.
11.    }
12.
13.        class Person {
14.
15.              constructor(name='用户名',age=0) {
16.                   this.name=name;
17.                    this.age=age;
18.              }
19.
20.
21.             play() {
22.                   console.log(`${this.name}会打游戏`);
23.             }
24.
25.        }
26.
27.
28.   class BwPer extends Per {
29.
30.          constructor(name,age) {
31.                super() //ES6继承必须要写super()
32.            }
33.
34.         HighSalary() {
35.
36.          }
37.
38.
39.   }

参考资料:
https://www.cnblogs.com/xiao-hong/p/3194027.html
https://www.cnblogs.com/lvmh/p/6104397.html
http://www.runoob.com/react/react-jsx.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • let和const,var特点:let有块作用域,不能重复定义,没有变量提升var没有块作用域,能重复定义,有变量...
    Live_60c3阅读 4,949评论 3 31
  • gitgit介绍git(https://github.com/)是分布式版本控制技术SVN是集中式管理版本控制技术...
    CDistance阅读 1,228评论 1 0
  • ES6全面总结 ES6新特性概览 本文基于lukehoban/es6features,同时参考了大量博客资料,具体...
    随风而去随遇而安阅读 2,865评论 0 1
  • 静水流深岂为守, 参天华盖若蚁蝼。 高山流水朝中隐, 月光美酒佳人游。 金蝉临凡牧童指, 神龙入海顿失愁。 嬉笑怒...
    海曲三少阅读 2,854评论 0 0
  • 根据当前的经验,通常抽奖活动类专题的结构包括以下几个部分: 主题Banner 简短有力的口号式标语,使用户快速感知...
    七个马甲阅读 3,947评论 0 0