Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"});
like image 935
ONYX Avatar asked Feb 26 '23 12:02

ONYX


1 Answers

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

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

Also see:

  • http://docs.jquery.com/Plugins/Authoring
like image 187
Emmett Avatar answered Mar 06 '23 23:03

Emmett