ES6的class方法基本用法 - NDweb的个人空间 - 开源中国

在ES5中我们通常通过构造函数,定义并生成新对象。例如:``` function Point(name,age){ this.name=name; this.age=age; } Point.prototype={ Who:function(){ return "My name is "+this...
阅读全文

ES6 关于对象的扩展 - 前端喵的个人空间 - 开源中国

今天来简单说下ES6 中对象的扩展 首先回顾传统的对象表示法```let person={ 'name':'zhang', 'age':'20', 'play':function(){ alert('play!') }}``` 再来看看ES6中写法```var name='zhang';var age=20;var p...
阅读全文

es6模块入门 - 我是钟钟的个人空间 - 开源中国

同步发布在我的个人网站:es6之前的模块?在es6之前,如果我们需要引入一个外部的库,可能是像下面这样子的:引入Jquery```<script src="https://cdn.bootcss.com/jquery/3.2.1/core.js"</script```然后在js中可以像下面这样使用:```$(function(){ $('.aaa').on...
阅读全文

ES6中Generator理解 - 不经年,知不足 - 开源中国

1\. 生成器函数声明   function  name(args){}; 2\. yield使用```function hello(){    console.log('before hello');  //可看到hello()并不会立刻执行函数, 到第一次next调用时才会    var name = yield 'please input your name'...
阅读全文

ES6箭头函数(Arrow Functions) - 筱飞的个人空间 - 开源中国

  ES6可以使用“箭头”(=)定义函数,注意是函数,不要使用这种方式定义类(构造器)。一、语法1\. 具有一个参数的简单函数```var single = a = asingle('hello, world') // 'hello, world'```2\. 没有参数的需要用在箭头前加上小括号```var log = () = {    alert('no par...
阅读全文

ES6的数组扩展 - 孟飞阳的个人空间 - 开源中国

Array.from()`Array.from`方法用于将两类对象转为真正的数组:类似数组的对象(arraylike object)和可遍历(iterable)的对象(包括ES6新增的数据结构Set和Map)。下面是一个类似数组的对象,`Array.from`将它转为真正的数组。```let arrayLike = { '0': 'a', '1': 'b', ...
阅读全文

ES6数组扩展 - 潘思研的个人空间 - 开源中国

ES6关于数组的扩展一共有以下8种,其中使用率比较高的有find()、entries()、keys()、values()和includes()。 Array.from() Array.of() 数组实例的copyWithin() 数组实例的find()和findIndex() 数组实例的fill() 数组实例的entries(),keys()和values()...
阅读全文

ES6 简单整理 - NDweb的个人空间 - 开源中国

1.变量声明 let 和 constlet与const 都是块级作用域, let```function name(){ let age = 12; //age只在name()函数中存在}``` const```const name = 'tom'name = 'jack'//再次赋值会报错``` 2.字符串模板 Es5```/...
阅读全文

ES6中class类的extends继承 - NDweb的个人空间 - 开源中国

在ES6中,class之间可以通过extends进行继承:我们先定义一个父类 Point:``` class Point{ constructor(color){ this.color=color; } }```之后再定义一个子类,让子类Test继承父类Point```class Test extends ...
阅读全文

ES6的Set()方法实现数组去重 - NDweb的个人空间 - 开源中国

```let arr=;let s1=new Set();s1.add(arr);s1.add(arr);s1.add(arr);s1.add(arr);s1.add(arr);let arr1=;for(let i of s1){ arr1.push(i);}console.log(arr1)```注意因为使用了ES6的语法,所以,运行时需要翻译...
阅读全文