// 不改变原有对象的属性和方法,为它添加新的属性和方法 var b = { bb: function() { console.log('bb') } } var decorator = function(obj,fn) { if(typeof obj.aa === 'function') { const oldFn = obj.aa obj.aa = function() { oldFn() fn() } } else { obj.aa = fn } } decorator(b,function() { console.log('aa') }) b.aa() console.log(b)