ONYX
ONYX

Reputation: 5859

overwrite default properties in jQuery plugin

could someone explain overwriting default properties and even extending them with jQuery inside my plugin example and also the closure function

$.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"});

Upvotes: 4

Views: 1149

Answers (1)

Emmett
Emmett

Reputation: 14337

You can use jQuery's extend to overwrite the default options:

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

Also see:

Upvotes: 8

Related Questions