ES2015 模板功能 数组写法+对象写法

let [name,age,str]=["daichen",18];

str=`${name}的年龄是${age}`;
alert(str);

翻译为es5:

"use strict";

var _ref = ["daichen", 18];
var name = _ref[0];
var age = _ref[1];
var str = _ref[2];


str = name + "\u7684\u5E74\u9F84\u662F" + age;
alert(str);

对象写法:

let me_class=function(){
    this.name="daichen";
    this.age="18";
}
let me=new me_class();
let str=`${me.name} ${me.age}`;
alert(str);

翻译为ES5

"use strict";

var me_class = function me_class() {
    this.name = "daichen";
    this.age = "18";
};
var me = new me_class();
var str = me.name + " " + me.age;
alert(str);

你可能感兴趣的:(Web前端)