javascript设计模式之装饰者模式(2)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>装饰者模式应用数据上报</title> </head> <body> <button type="button">点击登录并上报数据</button> </body> <script> var showDialog = function(){ console.log('显示登录弹窗'); } var log = function(){ console.log('计数上报'); } var after = function(fn, afterFn){ return function(){ var ret = fn.apply(this, arguments) afterFn.apply(this, arguments) return ret; } } showDialog = after(showDialog, log) document.getElementById('btn').onclick = showDialog; </script> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/90a6805e62409470549bebb1de02a811.html