Function actsasdecorator (object) {object. setupdecoratorfor = function (method) {If (! ('Ininal _ '+ method in object) {object ['original _' + method] = object [Method]; object ['before _ '+ method] = []; object ['after _ '+ method] = []; object [Method] = function () {var I; var B = This ['before _' + method]; vaR A = This ['after _ '+ method]; var RV; for (I = 0; I <B. length; I ++) {B [I]. call (this, arguments);} Rv = This ['ininal _ '+ method]. apply (this, arguments); for (I = 0; I <. length; I ++) {A [I]. call (this, arguments) ;}return RV ;}}; object. before = function (method, f) {object. setupdecoratorfor (method); object ['before _ '+ method]. unshift (f) ;}; object. after = function (method, f) {object. setupdecoratorfor (method); object ['after _ '+ method]. push (f) ;};}/** invoking */function test () {This. say1 = function (s) {alert (s);} This. say2 = function (s) {alert (s) ;}} var T = new test (); actsasdecorator (t); T. before ("say1", beforehander); T. after ("say2", afterhander); test ();