- (function(){
- var jQuery = window.jQuery = window.$ = function( selector, context ) {
- //jQuery的构造函数是它原型上的init方法
- //当调用$()时就会用jQuery.init创建一个实例
- return new jQuery.fn.init( selector, context);
- };
- jQuery.fn = jQuery.prototype = {
- init:function(selector, context){
- alert(selector);
- },
- add : function() {
- return this;
- }
- }
- //由于$()对象继承的是init的prototype上的方法,所以不会继承jQuery.prototype上的方法
- //为了实现原型的继承,所以把jQuery.fn赋值给了jQuery.fn.init.prototype
- //这样$()对象就会继承jQuery.prototype上的所有方法了
- jQuery.fn.init.prototype = jQuery.fn;
- })();
- $("dd").add();
- //该片段来自于http://www.codesnippet.cn/detail/171020136471.html
来源: http://www.codesnippet.cn/detail/171020136471.html