博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javascript实现AOP
阅读量:6978 次
发布时间:2019-06-27

本文共 688 字,大约阅读时间需要 2 分钟。

hot3.png

// 通过扩展Function.prototype实现的。Function.prototype.before = function(beforeFn){    var _self = this;    return function(){        beforeFn.apply(this,arguments); // 先提前调用 before方法        return _self.apply(this,arguments); // 返回自身对象。    }}Function.prototype.after = function(afterFn){    var _self = this;    return function(){        var ret = _self.apply(this,arguments); // 先执行自身        afterFn.apply(this,arguments); // 执行后续方法        return ret; // 返回自身对象    }}
var test = function(){    console.log('hello');}test = test.after(function(){    console.log('after');})test = test.before(function(){    console.log('before');});test();

// 最后

204416_2nGr_1037170.png

转载于:https://my.oschina.net/bosscheng/blog/472662

你可能感兴趣的文章
javascript promise编程
查看>>
python自定义库文件路径
查看>>
spring security之httpSecurity 专题
查看>>
org.springframework.jdbc.datasource
查看>>
HDU 4467 分块
查看>>
slurm用户快速入门手册
查看>>
使用最小堆优化Dijkstra算法
查看>>
选择排序
查看>>
韩顺平_JAVA_视频教程_下载(打开迅雷,直接复制链接地址即可下载)
查看>>
[android] 从gallery获取图片
查看>>
[日常] Go语言圣经-函数递归习题
查看>>
泛型中? super T和? extends T的区别
查看>>
Unity3D心得分享
查看>>
excel增加上一列的数值(日期)
查看>>
Java数据结构一 —— Java Collections API中的表
查看>>
2018-2019-1 20165206 《信息安全系统设计基础》第4周学习总结
查看>>
js canvas游戏初级demo-上下左右移动
查看>>
css3选择器二
查看>>
初学Java——选择
查看>>
转 微博 linux中ctime,mtime,atime的区别
查看>>