ES6中的Class

# ES6中的Class

ES6 的 class 机制

class Widget {
 constructor(width, height) {
  this.width = width || 50;
  this.height = height || 50;
  this.$elem = null;
 }

 render($where) {
  if (this.$elem) {
   this.$elem.css({
    width: this.width + 'px',
    height: this.height + 'px'
   }).appendTo($where);
  }
 }
}

class Button extends Widget {
 constructor(){

 }
 render() {

 }
 onClick() {
  
 }
}
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
26
27
28
上次更新: 2022/8/9 下午2:18:14