The difference between the use of Jquery package functions $.extend(), $.fn and $.fn.extend()

<div id="myDiv"></div>
<script src="./js/jquery.min.js"></script>
<script type="text/javascript">

/*(function(){
     alert("立即执行");
})();

(function(parameter){
    alert(parameter);
})("立即执行函数传递参数");

*/

(function($,window,document,undefined){})
{
   
//fn原型:查看jquery可知 $.fn = $.prototype 
// $.fn = $.prototype ={ 
//    init: function( selector, context ){//....  
//    //...... 
// };

//$.extend({abc:abc,});//$.extend(object);为扩展jquery类本身.为类添加新的方法
$.abc=abc;//对jQuery类本身扩展了一个abc()方法 $.abc()调用


// $.fn.extend(object);给jquery对象实例添加方法
 $.fn.extend({
        test:test,
    });
 $.fn.test=test;


function test(){
    alert($(this).attr("id"));
    }
   
 function abc(){
    	 alert("abc");
    }

}($,window,document);
 

$("#myDiv").test();




</script>

 

Guess you like

Origin blog.csdn.net/qq_39418742/article/details/102604796