'use strict' function school(){ console.log('師徒'); } @school class Student{ constructor(name){ this.name=name } study(){ console.log(this.name+" is studying"); } }
npm install babel-plugin-transform-decorators-legacy --save-devhtml
.babelrc=>修改成"plugins": ["transform-decorators-legacy"]jquery
在html文件裏引用:npm
function school(target){ target.schoolName="師徒"; } function hometown(diq){ return function(target){ target.home=diq; } } function studyke(kemu){ return function(target){ target.ke=kemu; } } @hometown("大廣靈") @school class Student { constructor(name){ this.name=name; } @studyke("jquery") study(){ console.log(this.name+"啦啦啦"+this.ke); } } console.log(Student.schoolName);//師徒. console.log(Student.home);//廣靈縣. let l = new Student("ss"); l.study();//ss在啦啦啦jquery. @school class Teacher { } console.log(Teacher.schoolName);//師徒.