我的插件不会覆盖默认值

我的插件不会覆盖默认值

问题描述:

我尝试实现我的第一个jquery插件(我是菜鸟).

I try to realise my first jquery plugin (Im a noob).

(function($){

    $.test = function(selector, settings){

        // settings

        var config = {
            'text': "test"
        };

        if ( settings ){$.extend(config, settings);}

        // variables

        var i = 0;
        alert(config.text);
    };

})(jQuery);

通话

$.test("juhu");

该脚本应警告"Juhu"而不是默认值"test".
怎么了?

The script should alert "Juhu" not the default value "test".
What is the fault?

有人可以帮我吗?

尝试以这种方式扩展:

if (settings) { config = $.extend( {}, config, settings ); }

然后使用config.text