javascript框架prototype和jquery模型总结和抽取
<div class="highlighter">[*]<script>
[*]functionjquery(o)
[*]{
[*]if(this===window)returnnewjquery(o);
[*]this.length=0;
[*]Array.prototype.push.apply(this,o);
[*]}
[*]
[*]jquery.prototype.each=function(fn)
[*]{
[*]vari,a=this;
[*]for(i=0;i<a.length;i++)
[*]fn.apply(a,,a]);
[*]};
[*]
[*]vara=jquery();
[*]a.each(function()
[*]{alert(this)
[*]});
[*]
[*]
[*]Function.prototype.bind=function(o)
[*]{
[*]var_f=this,a=[];
[*]Array.prototype.push.apply(a,arguments);
[*]a.shift();
[*]returnfunction()
[*]{
[*]varb=[];
[*]Array.prototype.push.apply(b,arguments);;
[*]_f.apply(o||_f,a.concat(b));
[*]};
[*]};
[*]
[*]functionkk()
[*]{
[*]vara=[];
[*]Array.prototype.push.apply(a,arguments)
[*]alert(a.join("\n"));
[*]//这里可以体现多态
[*]this.each(function()
[*]{
[*]alert(this+10);
[*]});
[*]}
[*]
[*]vartest1=kk.bind(a,44,88);
[*]test1(66);
[*]</script>
页:
[1]