We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
网络资源注明来源
The text was updated successfully, but these errors were encountered:
修饰器(Decorator)是一个函数,用来修改类的行为。这是ES7的一个提案,目前Babel转码器已经支持
我们在游戏大型项目种经常会用到的方法,现在es6直接支持
npm install babel-plugin-transform-decorators-legacy --save-dev
完事配置一下babelrc文件
"plugins": ["transform-decorators-legacy"]
装饰器本质是一个函数
@hometown hometown()
装饰对象可以使用多个装饰器
@hometown("山西") @school class Student{ constructor(name){ this.name=name; } @studyke("HTML") study(){ console.log(this.name+" is studying"+this.ke+"!") } }
装饰器可以带参数
function hometown(diqu){ //target.home="广灵"; return function(target){ target.home=diqu; } } @hometown("山西") class...
装饰器修饰 类
function school(target){ console.log("123") target.schoolName="师徒课堂"; } function hometown(diqu){ //target.home="广灵"; return function(target){ target.home=diqu; } } function studyke(kemu){ return function(target){ target.ke=kemu; } } @hometown("山西") @school class Student{ constructor(name){ this.name=name; } @studyke("HTML") study(){ console.log(this.name+" is studying"+this.ke+"!") } } console.log(Student.schoolName); console.log(Student.home); let l=new Student("xiaoA"); l.study(); @school function Teacher(){ }
以上就是这篇文章的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。
Sorry, something went wrong.
No branches or pull requests
网络资源注明来源
The text was updated successfully, but these errors were encountered: