Skip to content

Instantly share code, notes, and snippets.

@ifyour
Last active November 4, 2019 10:16
Show Gist options
  • Save ifyour/cec88ec11ebe80e02b54e84db31331df to your computer and use it in GitHub Desktop.
Save ifyour/cec88ec11ebe80e02b54e84db31331df to your computer and use it in GitHub Desktop.
装饰器模式实现数据埋点
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