1: 引入了class 定义方法可以不用function了
class Project {
constructor(name) {
this.name = name;
}
2:支持继承 extends 是js原型继承 OO面向对象的福音
class WebProject extends Project {
constructor(name, technologies) {
super(name);
this.technologies = technologies;
}
3:引入了模块(export/import) 如果你想将所有js放在一个文件中,或者你要在应用的不同地方使用相同的功能,你就要使用模块,记住魔
术的关键词是export,在你的函数之前使用export。
// modules/helper.js
export function arrayToString(param) {
// some implementation
}
// application.js
import { arrayToString } from 'modules/helpers';
class WebProject extends Project {
constructor(name, technologies) {
super(name);
this.technologies = technology;
}
4: let和const
总结:var是function-scoped,而let是 block-scoped.
const是创建常量使用
5:for of 值遍历 ES6中新引入的for of循环功能相似,不同的是每次循环它提供的不是序号而是值
var someArray = [ "a", "b", "c" ];
for (v of someArray) {
console.log(v);//输出 a,b,c
}
6:Map,Set 和 WeakMap,WeakSet等集合类型
总结:写es6规范的js代码越来越像写后台的OO代码了 前后端差异越来越小了
class Project {
constructor(name) {
this.name = name;
}
2:支持继承 extends 是js原型继承 OO面向对象的福音
class WebProject extends Project {
constructor(name, technologies) {
super(name);
this.technologies = technologies;
}
3:引入了模块(export/import) 如果你想将所有js放在一个文件中,或者你要在应用的不同地方使用相同的功能,你就要使用模块,记住魔
术的关键词是export,在你的函数之前使用export。
// modules/helper.js
export function arrayToString(param) {
// some implementation
}
// application.js
import { arrayToString } from 'modules/helpers';
class WebProject extends Project {
constructor(name, technologies) {
super(name);
this.technologies = technology;
}
4: let和const
总结:var是function-scoped,而let是 block-scoped.
const是创建常量使用
5:for of 值遍历 ES6中新引入的for of循环功能相似,不同的是每次循环它提供的不是序号而是值
var someArray = [ "a", "b", "c" ];
for (v of someArray) {
console.log(v);//输出 a,b,c
}
6:Map,Set 和 WeakMap,WeakSet等集合类型
总结:写es6规范的js代码越来越像写后台的OO代码了 前后端差异越来越小了