Decorator(修饰器/装饰器)是es6提出的语法糖,用于修改类的行为。不过目前主流浏览器都没有很好的支持,我们需要用babel来转换为浏览器能识别的语言。在这篇文章中将介绍decorator的基础用法和一些应用实例。
1.修饰类
(1) 基础用法
@testable
class MyClass{}
function testable(target){
target.isTestable=true
}
console.log(MyClass.isTestable) // true
贴一下babel转换后的代码,
var _class;
let MyClass = testab