作用:

可以给原有对象的身上添加新的属性方法

可以让对象或者组件进行扩展

示例:

class Person{constructor(name,selfSkill){this.name = namethis.selfSkill = selfSkill}run = '会走路'}//所有人类都有的共同特性和技能let wjt = new Person('王惊涛','写代码')let mashi = new Person('马师','烹饪')//定义一个装饰器函数,给所有被构建的实例原型上加上公共属性,比如所有人都会吃饭睡觉const decorateFun = function(entiry,skillName,skillValue){ entiry.prototype[skillName] = skillValue}decorateFun(Person,'sleep','睡觉')decorateFun(Person,'eat','吃饭')console.log(wjt,'wjt')console.log(mashi,'mashi')