装饰器
类的装饰
@decortator
class A {}
// 等同于
class A {}
A = decorator(A) || A// minxins.js
export function mixins(...list) {
return function (target) {
Object.assign(targe.prototype, ...list)
}
}
// main.js
import { mixins } from './mixins'
const Foo = {
foo () { console.log('foo') }
}
@mixins(Foo)
class MyClass {}
let obj = new MyClass()
obj.foo() // 'foo'方法的装饰
装饰器不能用于函数
最后更新于