What might be a reason of overriding function using jQuery.extend?

房东的猫 提交于 2019-12-05 20:40:38

You need to change this:

$.fn.modal = $.extend(function(option) {
    // your code ...
}, $.fn.modal);

for this:

$.extend($.fn.modal, function(option) {
    // your code ...
});

TL;DR

$.extend(a, b) copies the content of b on a (modifying it's content), and if any repeated, then the property of b remains. Also, it returns the value of a.

So, If you have this:

hello    = { unique_on_hello: 'hola',  message: 'hello message' }
world    = { unique_on_world: 'mundo', message: 'WORLD MESSAGE' }
response = $.extend(hello, world)

The values of each one will be:

hello    // {unique_on_hello: "hola", message: "WORLD MESSAGE", unique_on_world: "mundo"}
world    // {unique_on_world: "mundo", message: "WORLD MESSAGE"}
response // {unique_on_hello: "hola", message: "WORLD MESSAGE", unique_on_world: "mundo"}

So, if you do f2 = $.extend(f1,f2); is the same as:

$.extend(f1, f2) // Copy properties of f2 to f1
f2 = f1

Source: https://api.jquery.com/jquery.extend/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!