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