Javascript 覆盖jQuery插件中的默认属性

Javascript 覆盖jQuery插件中的默认属性,javascript,jquery,Javascript,Jquery,有人能解释一下在我的插件示例和闭包函数中覆盖默认属性,甚至用jQuery扩展它们吗 $.fn.myObject = function(overwriteProperties) { var properties = {myproperty1: "defaultvalue"} // overwrite properties here function doStuffHere() { } return (function() { return

有人能解释一下在我的插件示例和闭包函数中覆盖默认属性,甚至用jQuery扩展它们吗

$.fn.myObject = function(overwriteProperties) {
    var properties = {myproperty1: "defaultvalue"}
    // overwrite properties here
    function doStuffHere() {

    }
    return (function() {
        return this; // does this part here refer to the object of myDiv
    });
} 
$('#myDiv').myObject({myPoperty1:"newValue"});
您可以使用jQuery覆盖默认选项:

var options = $.extend({}, defaults, options);
另见:


仍然需要演示,尤其是扩展中的expty对象function@littleMan看看var options=$.extend({},默认值,options{});这样,如果options对象为null或未定义,将使用空对象,因此不会覆盖任何属性。