对于jQuery的整体架构,经典之处有三:1、jQuery的无new构建2、jQuery的链式调用3、jQuery的插件接口想必兄弟姐妹们也觉得这架构不错哈,但有时又畏惧去拜读大量的jQuery源码,只好对它敬而远之了。哈哈,今天我就将其jQuery架构提炼出来,和大家一同分析研 ...
对于jQuery的整体架构,经典之处有三:
1、jQuery的无new构建
2、jQuery的链式调用
3、jQuery的插件接口
想必兄弟姐妹们也觉得这架构不错哈,但有时又畏惧去拜读大量的jQuery源码,只好对它敬而远之了。
哈哈,今天我就将其jQuery架构提炼出来,和大家一同分析研究下,jQuery是怎么实现这三个经典之处的。
提炼的代码如下:
1 <!DOCTYPE html> 2 <head> 3 <title>jQuery</title> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 5 </head> 6 <body> 7 <script> 8 9 (function(window){10 var temp=window.$=function(){11 return new temp.fn.init();12 };13 temp.fn=temp.prototype={14 init:function(){15 return this;16 },17 attr:function(){18 console.log(1);19 return this;20 }21 }22 temp.fn.init.prototype = temp.fn;23 })(window);24 //执行25 console.log( $ );26 27 </script>28 </body>29 </html>
原标题:jQuery架构剖析
关键词:jquery
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。