fe-interview icon indicating copy to clipboard operation
fe-interview copied to clipboard

[jQuery] jquery.extend与jquery.fn.extend的区别?

Open haizhilin2013 opened this issue 6 years ago • 2 comments

[jQuery] jquery.extend与jquery.fn.extend的区别?

haizhilin2013 avatar Sep 22 '19 12:09 haizhilin2013

jquery.extend是扩展jquery这个类的方法,类似于c#中的静态方法;jquery.fn.extend是扩展jquery这个类的实例的方法

zhaoyanxing avatar Jul 15 '21 03:07 zhaoyanxing

✂【回答】

  • jQuery 本身的扩展方法:$.extend
  • jQuery 所选对象的方法:$.fn.extend

🖊【便签】 举个栗子:

// 1. jQuery 本身的扩展方法:$.extend
$.helloWorld = function () {
  console.log("@^0^@,我是 jQuery 本身的扩展方法");
}
// 2. jQuery 所选对象的方法:$.fn.extend
$.fn.helloWorld = function () {
  console.log("@^0^@,我是 jQuery 所选对象的方法");
}

$("div").helloWorld();
$.helloWorld();

♡【关注】 https://blog.csdn.net/Hewes

Hub-ShengQing avatar Aug 05 '22 03:08 Hub-ShengQing