There are two methods of jquery core:
1, $.extend (object) can be understood to add a static method for jquery.
2. $.fn.extend (object) can be understood to add a method to a jquery instance.
Basic use
$.extend ({ function() { alert (one); } }) $.fun1 (); $.fn.extend ({ function() { alert (); } }) $ (this). fun2 (); // equivalent to function () { alert; } $ (this). FUN3 ();
The difference between jquery (function () {}) and (function ($) {}) (jquery)
1. JQuery (function () {}) is equivalent to $ (document). Ready (function () {}) when the DOM element is loaded to complete the execution of the method
2, (function ($) {}) (JQuery) is equivalent to
var fun = function ($) {};
Fun (jQuery);
An anonymous function is defined, where jquery represents the function argument. Usually used in jquery plug-in development, the role of defining the private domain plug-in.
<div id= "link" ><a href= "#" >jQuery</a></div>
<script src= "Http://libs.baidu.com/jquery/1.9.1/jquery.min.js" ></script>
<script>
//Step01 Defining the scope of jquery(function($) { varDefaults = {//Step01 Defining the scope of jqueryAnimatepadding:20, Hovercolor:"#f90" };//defining methods in plugins varShowLink =function(obj) {$ (obj). Append ("2222"); } //extension method name for STEP02 plug-in$.fn.paddingslide =function(options) {varoptions = $.extend (defaults, options);//step03-b Merge User custom properties, default properties //STEP4 support jquery selector $ (this) this //STEP5 supports link invocation by supporting the definition of a link call return. Such calls are supported: $ ("#fixed-floor"). Paddingslide (). CSS (', '); return This. each (function() {//the This-->jquery object, $ (this), is used for DOM objects, varobj = $ ( This); varItem = $ ("a", obj); Item.hover (function() { $( This). CSS ("Color", Options.hovercolor); $( This). Stop (). Animate ({paddingLeft:options.animatePadding}, 500); ShowLink ( This); },function() { $( This). CSS ("Color", "" "); $( This). Stop (). Animate ({paddingleft:0}, 500); }); }) };}) (JQuery);
$ (function () {
$ ("#link"). Paddingslide ();
})
</script>
jquery plugin notation