YoungZhang's Blog


  • Home

  • About

  • Tags

  • Categories

  • Archives

初试ES6之Class

Posted on 2018-05-09 | In ES6 |

Class基础知识

语法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 方法一 Class声明
class Point {
construstor(x, y) {
this.x = x;
this.y = y;
}

toString() {
return '(' + this.x + ',' + this.y + ')';
}
}

// 方法二 Class表达式
let person = new class {
constructor(name) {
this.name = name;
}

sayName() {
console.log(this.name);
}
}('张三');

person.sayName(); // "张三"
// person是一个立即执行的类的实例

类的数据类型是函数,因为类本身指向构造函数,类的方法都定义在prototype属性上面,可以使用Object.assign方法一次向类添加多个方法

Read more »

由一道算法带进ES6之SetMap

Posted on 2018-05-08 | In ES6 |

Set:

构造函数(可生成Set数据结构),类似数组,成员值唯一。

Set实例具有的属性:

1.Set.prototype.constructor:默认Set

2.Set.prototype.size:成员总数

Read more »
1…45

YoungZhang

越努力越幸运~

42 posts
13 categories
64 tags
GitHub E-Mail Google Instagram
© 2018 YoungZhang
Powered by Hexo
|
Theme — NexT.Pisces v5.1.4