es6学习笔记
文章平均质量分 65
es6基础学习,涵盖一些基础用法和实例
SirM2z
这家伙很懒,留下了一句话~
展开
-
ES6学习笔记(八)--Class
class基本语法//ES5function Point(x,y){ this.x = x; this.y = y;}Point.prototype.toString = function () { return '(' + this.x + ', ' + this.y + ')';};//ES6class Point { //constructor是类的默认方法,通过new原创 2016-06-01 17:19:58 · 1067 阅读 · 0 评论 -
ES6学习笔记(七)--Generator函数与Promise对象
Generator函数执行Generator函数会返回一个遍历器对象,也就是说,Generator函数除了状态机,还是一个遍历器对象生成函数。返回的遍历器对象,可以依次遍历Generator函数内部的每一个状态。function* helloWorldGenerator() { yield 'hello'; yield 'world'; return 'ending';}var hw原创 2016-06-01 17:18:47 · 2282 阅读 · 0 评论 -
ES6学习笔记(六)--set,map数据结构和for...of遍历
Set新的数据解构,成员值是唯一的//不能添加相同的值var s = new Set();[2, 3, 5, 4, 5, 2, 2].map(x => s.add(x));for (let i of s) { console.log(i);}// 2 3 5 4//去除相同的值var set = new Set([1, 2, 3, 4, 4]);[...set]// [1, 2, 3原创 2016-06-01 17:18:01 · 5786 阅读 · 0 评论 -
ES6学习笔记(五)--函数与对象
函数参数的默认值基本用法function log(x, y = 'World') { console.log(x, y);}log('Hello') // Hello Worldlog('Hello', 'China') // Hello Chinalog('Hello', '') // Hello与解构赋值默认值结合使用function foo({x, y = 5}) { conso原创 2016-06-01 17:17:11 · 3219 阅读 · 0 评论 -
ES6学习笔记(四)--数值与数组
数值的扩展Number.isFinite(), Number.isNaN()与传统的全局方法isFinite()和isNaN()的区别在于,传统方法先调用Number()将非数值的值转为数值,再进行判断,而这两个新方法只对数值有效,非数值一律返回falseNumber.parseInt(), Number.parseFloat()ES6将全局方法parseInt()和parseFloat(),移植到原创 2016-06-01 17:15:01 · 6025 阅读 · 0 评论 -
ES6学习笔记(三)--字符串扩展
字符串扩展for…of循环遍历字符串let text = 'abc'for (let i of text) { console.log(i);}//a//b//c新增确定一个字符串是否包含在另一个字符串中,es5中只有indexOfincludes():返回布尔值,表示是否找到了参数字符串startsWith():返回布尔值,表示参数字符串是否在源字符串的头部endsWith()原创 2016-06-01 17:14:24 · 2001 阅读 · 0 评论 -
ES6学习笔记(二)--解构赋值
解构赋值数组的解构赋值let [foo, [[bar], baz]] = [1, [[2], 3]];foo // 1bar // 2baz // 3let [ , , third] = ["foo", "bar", "baz"];third // "baz"let [x, , y] = [1, 2, 3];x // 1y // 3let [head, ...tail] = [1, 2,原创 2016-06-01 17:13:42 · 1033 阅读 · 0 评论 -
ES6学习笔记(一)--let和const命令
let和const命令let和const声明的变量只在代码块内有效{ let a = 10; var b = 1;}a // ReferenceError: a is not defined.b // 1不存在变量提升变量一定要在声明后使用,否则报错var tmp = 123;if (true) { tmp = 'abc'; // ReferenceError let tmp原创 2016-06-01 17:11:21 · 1776 阅读 · 0 评论