Skip to content

Commit 9120e5f

Browse files
author
廖海兵
committed
学习es6
1 parent 68c03f8 commit 9120e5f

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
"import/default": 0,
4949
"import/no-duplicates": 0,
5050
"import/named": 0,
51+
"no-proto": 0,
52+
"no-prototype-builtins": 0,
5153
"import/namespace": 0,
5254
"import/no-unresolved": 0,
5355
"import/no-named-as-default": 2,

src/containers/Es6/Es6.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,50 @@ export default class Es6 extends Component {
1111

1212
componentWillMount() {
1313
// this.testDemo();
14+
this.testClassDemo();
1415
}
1516
printLine(args) {
16-
console.log('-------------' + (args || '') + '-------------------');
17+
console.log('-------------------' + (args || '') + '-------------------');
1718
}
19+
20+
testClassDemo() {
21+
class Point {
22+
constructor(x, y) {
23+
this.x = x;
24+
this.y = y;
25+
}
26+
toString() {
27+
const value = 'x:' + this.x + ' y:' + this.y;
28+
return value;
29+
}
30+
}
31+
Object.assign(Point.prototype, {
32+
sayHello() {
33+
console.log('say hello');
34+
}
35+
});
36+
const p = new Point(1, 2, 'bbc');
37+
this.printLine(p.toString());
38+
p.sayHello();
39+
const a = p.__proto__.hasOwnProperty('toString');
40+
console.log(a);
41+
42+
class GetSetClass {
43+
get(name) {
44+
return this[name];
45+
}
46+
set(name, value = '默认值') {
47+
this[name] = value;
48+
}
49+
}
50+
51+
const gs = new GetSetClass();
52+
gs.set('name01', '张三');
53+
gs.set('name00');
54+
console.log('--------', gs.get('name00'));
55+
console.log('--------', gs.get('name01'));
56+
}
57+
1858
testDemo() {
1959
const arr = [1, 2, 3];
2060
const [a, b, c] = arr;

src/router/router.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BrowserRouter as Router, Route } from 'react-router-dom';
44
import { Utility, Navbar } from 'components';
55
import pageComponent from 'containers';
66
const {
7-
App, Default, UserInfo, Counter, Home, Page1, Page2, Page3, Page4
7+
App, Default, UserInfo, Counter, Home, Page1, Page2, Page3, Page4, Es6,
88
} = pageComponent;
99
const AppCfg = require('../config');
1010

@@ -46,6 +46,7 @@ const getRouters = () => (
4646
<Route path="/page4" component={CreateComponent(Page4)} />
4747
<Route path="/counter" component={CreateComponent(Counter)} />
4848
<Route path="/userinfo" component={CreateComponent(UserInfo)} />
49+
<Route path="/es6" component={CreateComponent(Es6)} />
4950
</App>
5051
</Router>
5152
);

0 commit comments

Comments
 (0)