js链式编程 实现对象方法动态扩展
(function(window){
window._MethodManager=function(obj)
{
//要处理的数据对象
this.data=obj;
//要添加的方法
this.methodNames=[];
}
//添加方法
_MethodManager.prototype.addMethod=function(name,fn)
{
//向原型链添加方法
_MethodManager.prototype[name]=fn;
//添加方法名称
this.methodNames.push(name);
return this;
}
})(window);
var fm=new _MethodManager("this is a data");
//添加方法一
fm.addMethod('methodone',function(){
var handdata=this.data;
//hand the data
this.data=this.data+" hand one ";
return this;
});
//添加方法2
fm.addMethod('methodtwo',function(){
var handdata=this.data;
//hand the data
this.data=this.data+" hand two ";
return this;
});
..添加其他的方法
console.dir(fm);
console.log(fm.methodone().data);
console.log(fm.methodone().methodtwo().data);
(function(window){
window._MethodManager=function(obj)
{
//要处理的数据对象
this.data=obj;
//要添加的方法
this.methodNames=[];
}
//添加方法
_MethodManager.prototype.addMethod=function(name,fn)
{
//向原型链添加方法
_MethodManager.prototype[name]=fn;
//添加方法名称
this.methodNames.push(name);
return this;
}
})(window);
var fm=new _MethodManager("this is a data");
//添加方法一
fm.addMethod('methodone',function(){
var handdata=this.data;
//hand the data
this.data=this.data+" hand one ";
return this;
});
//添加方法2
fm.addMethod('methodtwo',function(){
var handdata=this.data;
//hand the data
this.data=this.data+" hand two ";
return this;
});
..添加其他的方法
console.dir(fm);
console.log(fm.methodone().data);
console.log(fm.methodone().methodtwo().data);
z子豪: PdfStamper对象的getOverContent,传入页码就可以addImage了,这样就让图片显示在上了
fengxianaa: 唉,完全看不懂