jquery extension method and difference

1.jQuery.extend: the method of jQuery itself

2.jQuery.fn.extend(object): jQuery selected object extension method

If we think of jQuery as a class, jQuery.extend() is the extended jQuery class, and jQuery.fn.extend() is the method on the extended object of this class, for example

//The following jQuery is uniformly replaced with $

//方式1
$.extend({
  say:function(){
    alert("我会说话!");
  }
});

//使用方法
$.say();

//方式2
$.fn.extend({
  say:function(){
    alert("我会说话!");
  }
});
//使用方式
$(".say").say();
//另外一种写法
(function($){
   $.fn.say=function(){
      alert("我会说话!");
   }
})(jQuery)

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939448&siteId=291194637