`
touchmm
  • 浏览: 1002742 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

javascript框架prototype和jquery模型总结和抽取

阅读更多
  1. <script>
  2. functionjquery(o)
  3. {
  4. if(this===window)returnnewjquery(o);
  5. this.length=0;
  6. Array.prototype.push.apply(this,o);
  7. }
  8. jquery.prototype.each=function(fn)
  9. {
  10. vari,a=this;
  11. for(i=0;i<a.length;i++)
  12. fn.apply(a[i],[a[i],a]);
  13. };
  14. vara=jquery([433,44,366]);
  15. a.each(function()
  16. {alert(this)
  17. });
  18. Function.prototype.bind=function(o)
  19. {
  20. var_f=this,a=[];
  21. Array.prototype.push.apply(a,arguments);
  22. a.shift();
  23. returnfunction()
  24. {
  25. varb=[];
  26. Array.prototype.push.apply(b,arguments);;
  27. _f.apply(o||_f,a.concat(b));
  28. };
  29. };
  30. functionkk()
  31. {
  32. vara=[];
  33. Array.prototype.push.apply(a,arguments)
  34. alert(a.join("\n"));
  35. //这里可以体现多态
  36. this.each(function()
  37. {
  38. alert(this+10);
  39. });
  40. }
  41. vartest1=kk.bind(a,44,88);
  42. test1(66);
  43. </script>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics