Comments (4)
好像这个特性挺乱的
from es6-code-style.
涉及到解构就乱了,很多人是hold不了解构的
除了解构外,其它的我其实还是能接受的……计算属性是必须用,因为有Symbol
这东西
from es6-code-style.
Symbol 这东西我还没有感受到啥明显的优势....
from es6-code-style.
我现在用Symbol
主要是2个方法:
- 我真的想要个私有属性,真的不想让某些二货拿到,特别是在我这边不推荐
_
开头的属性命名 - 和decorators配合设置一些“本来不想要方法名”的方法
- 通用基类、外部介入的功能需要一个属性,但很担心和别的冲突,比如
mini-event
可以要一个属性管理所有事件,但因为使用场景太多总感觉起啥名字都有可能冲突,那不如上Symbol
提供个代码示例看看我们现在的玩法:
class CustomView extends BaseView {
@on('table', 'sort')
[Symbol('onTableSort')](e) {
this.sortData(e.field);
this.repaintTable();
}
@on('pager', 'pagechange')
[Symbol('onPagerPageChange'])() {
this.reloadData(this.pager.get('page'));
this.repaintTable();
}
}
我们不再找地方一行一行写get('xxx').on
也不用uiEvents
之类的属性了,全部用decoator往方法上加来绑定事件,看上去会更接近声明式编程一些,这种情况下,这些事件处理的方法是不想要任何名字的,也避免和其它的冲突,所以就用Symbol
了
from es6-code-style.
Related Issues (11)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from es6-code-style.