-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo1.js
49 lines (42 loc) · 1.21 KB
/
demo1.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React, {Component} from 'react';
class Demo1 extends Component {
constructor(props) {
super(props);
this.handleClick3 = this.handleClick3.bind(this);
}
handleClick1(arg, e) {
console.log('-----bind:');
console.info(e);
console.log(this);
console.log(arg);
}
handleClick2(e) {
console.log('-----双冒号(::):')
console.log(e);
console.log(this)
}
handleClick3(e) {
console.log('------constructor中声明');
console.log(e);
console.log(this)
}
handleClick4 = (e) => {
console.log('-------箭头函数');
console.log(e);
console.log(this)
};
render() {
return (
<div className="demo1">
<button onClick={this.handleClick1.bind(this, 'bind')}>bind方法</button>
<br/>
<button onClick={::this.handleClick2}>::双冒号语法</button>
<br/>
<button onClick={this.handleClick3}>构造器内声明</button>
<br/>
<button onClick={this.handleClick4}>箭头函数</button>
</div>
);
}
}
export default Demo1;