Last active
November 4, 2019 10:16
-
-
Save ifyour/cec88ec11ebe80e02b54e84db31331df to your computer and use it in GitHub Desktop.
装饰器模式实现数据埋点
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.after = function(afterFn) { | |
const __this = this; | |
return function() { | |
const ret = __this.apply(this, arguments); | |
afterFn.apply(this, arguments); | |
return ret; | |
} | |
} | |
let showLogin = function() { | |
console.log('打开登录框'); | |
} | |
const log = function() { | |
console.log(`上报标签:${this.getAttribute('tag')}`); | |
// (new Image).src = 'https://xxx.com'// 上报给后端接口 | |
} | |
showLogin = showLogin.after(log); | |
document.getElementById('button').onclick = showLogin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment