zoukankan      html  css  js  c++  java
  • Vue--vue中常用的ECMAScript6语法

    1、对象的写法

    1  es5中对象: {add:add,substrict:substrict}
    2  es6中对象: {add,substrict}  注意这种写法的属性名称和值变量是同一个名称才可以简写,否则要想es5那样的写法,例如: {addFun:add}

    2、在对象中的方法的写法

    1  es5中对象: {add:function(){},substrict:function(){}}
    2  es6中对象: {add(){},substrict(){}}

    3、对象的导出写法

    1 es5两种形式:
    2          1、module.exports = fucntion (){};
    3          2、exprots.add =  fucntion (){};
    4 
    5 es6中写法:
    6         1、export default{
    7             add(){}
    8         }
    9         2、export fucntion add(){} 相当于 将add方法当做一个属性挂在到exports对象

    4、对象的导入

     1         es5: var add  = require('./calc.js');
     2         es6:
     3         如果导出的是:export default{ add(){}}
     4         那么可以通过  import obj from './calc.js'
     5 
     6         如果导出的是:
     7         export fucntion add(){}
     8         export fucntion substrict(){}
     9         export const PI=3.14
    10 
    11         那么可以通过按需加载 import {add,substrict,PI} from './calc.js'

     

    5、es6中的箭头函数的写法

    1         箭头的演变过程:
    2         //需求:利用函数实现倒序排列
    3         [2,1,3].sort(function(x,y){return y - x;});
    4 
    5         //用箭头函数实现 =>读 goes to
    6         [2,1,3].sort((x,y)=>{return y - x;});
    7         [2,1,3].sort((x,y)=> {x++;y++; y - x;});
    8         [2,1,3].forEach(x=> {console.log(x)});
  • 相关阅读:
    洛谷P2762 太空飞行计划问题
    网络流24题 gay题报告
    洛谷P1712 区间
    洛谷P2480 古代猪文
    10.9zuoye
    面向对象类编程,计算分数
    请输入验证码优化版
    面向对象式开发程序
    直接选择排序与反转排序
    随机数产生原理
  • 原文地址:https://www.cnblogs.com/TigerZhang-home/p/8962110.html
Copyright © 2011-2022 走看看