javascript - Can class attributes and methods be separated into files in ES6?
仅有的幸福
仅有的幸福 2017-06-28 09:28:59
0
1
756

To define class in es6, you can do this

class A { x = 1; y = 2; z = 3; mx () { // ... } my () { // ... } mz () { // ... } }

When there are more and more A class attribute methods, it is found that the entire file has a large amount of code. Can some properties and methods be divided into a single file (for example, x and mx are divided into one x.js file, y and my are divided into one y.js file...)

If you use extends, you will find a problem. Properties cannot be shared, and neither can methods.

Can we combine (x.js / y.js / ...) into A when defining class A?

仅有的幸福
仅有的幸福

reply all (1)
阿神

MixinMode

In short, it is to merge theprototypeattributes of several classes, and the last big class can inherit this merged class.

Ruan Yifeng’s ES6 tutorial has a sample program, you can refer to: Mixin-pattern implementation

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!