2

Working on a simple calendar script, trying to make it possible for events to be posted to the proper day; however the jQuery $.extend is not extending my options object. Here is the snippet from the HTML file:

$("#cal").calendar({
    month: 2,
    events: [{
        date: "2013-4-10",
        workorder: 1234567890,
        district: 01,
        range: "2:00pm - 4:00pm",
        appNotes: "This is just a sample of some notes... end",
        installer: "John Doe",
        cityNotes: "This is just another sample of some notes... end"
    }, {
        date: "2013-4-1",
        workorder: 1234567890,
        district: 01,
        range: "3:00pm - 5:00pm",
        appNotes: "This is just a sample of some notes... end",
        installer: "John Doe",
        cityNotes: "This is just another sample of some notes... end"
    }]
});

And the beginning of my plug in:

(function($){
    $.fn.calendar = function(options){
        var defaults= {
            month: null,
            prev: "prevMonth",
            curr: "currMonth",
            next: "nextMonth",
            events: []
        }, options = $.extend(defaults, options);
        return($(this).each(function(){
            var obj = $(this),
            // Etc...

I'm able to access properties of the object, however it is not being extended as thought. Any ideas?

3
  • I've done it a million times this way and never had a problem @jahroy Commented Apr 5, 2013 at 1:02
  • Yep... @SeanVieira looks to have the right answer. About to delete my silly comment. Commented Apr 5, 2013 at 1:02
  • I thank you for taking a look either way @jahroy Commented Apr 5, 2013 at 1:04

2 Answers 2

4

jQuery.extend extends the first object passed in - rather than doing $.extend(defaults, options) do $.extend({}, defaults, options).

Sign up to request clarification or add additional context in comments.

Comments

1
(function($){
    $.fn.calendar = function(options){
        var defaults= {
            month: null,
            prev: "prevMonth",
            curr: "currMonth",
            next: "nextMonth",
            events: []
        };
        options = $.extend(defaults, options);

Also: remember that the Target is the first object... so in this example, defaults would have been extended with options...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.