var person = {};
obj.name = "xxx";
obj.sex = "yyy";
obj.myFunction = function(){ alter(obj.name); }
var ePer = {};
ePer ['field'] = 'field';
ePer.myFunction = function(){ alter(ePer .'field') };
ePer.extendBy = function(parant){
for(var i in person ){
if(parant[i]=="undefine")continue;
extendPer[i] = parant[i];
}
}
//进行继承 或重载
ePer.extendBy(person);
var person2 = function(){
this.field1 = "xxx";
};
person2.prototype.myFn = function(){
return this.field1;
}
//多继承
ePer.extendBy(new person2());
/****************************************************
动态 javascript aop 呵呵
*****************************************************/
//动态运行时的拦截代码织入 操作类
var aopEmbed = function(){
/** 拦截前
* exeAop 自定义拦截代码
* aimObj 被拦截的类
* aimMethod 所拦截的目标方法名
* scope 拦截方法执行时 的运行作用域
**/
this.beforEmbed = function(exeAop,args1,aimObj,args2,aimMethod,scope){
this['BScope'] = aimObj[aimMethod];
aimObj[aimMethod] = function(){
exeAop.call(scope,args1);
this['BScope'].call(scope,args2);
}
}
//拦截后
this.afterEmbed = function(exeAop,args1,aimObj,args2,aimMethod,scope){
this['BScope'] = aimObj[aimMethod];
aimObj[aimMethod] = function(){
this['BScope'].call(scope,args2);
exeAop.call(scope,args1);
}
}
}
javascript 动态织入 拦截(aop) 代码与动态继承
最新推荐文章于 2023-11-02 20:05:06 发布
本文探讨了JavaScript中对象继承的实现方式,并通过具体示例介绍了如何利用原型链实现继承及多继承。此外,还深入讲解了动态AOP(面向切面编程)的实现原理与应用,展示了如何在运行时对方法进行拦截。
1372

被折叠的 条评论
为什么被折叠?



