作用:
可以给原有对象的身上添加新的属性方法
可以让对象或者组件进行扩展
示例:
class Person{
constructor(name,selfSkill){
this.name = name
this.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')


















![[经验] 玄殿社区qq堂4.2 #笔记#媒体](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fwww.hao123rr.com%2Fzb_users%2Fcache%2Fly_autoimg%2F%25E7%258E%2584%25E6%25AE%25BF%25E7%25A4%25BE%25E5%258C%25BAqq%25E5%25A0%25824.2.jpg&pos_id=nlcdhup0)

