kilicos
kilicos

Reputation: 99

how to override dojo function

I'd like to correct a problem of incorrect week number in dojox/calendar/Calendar. I know what to change => exports._getWeekOfYear function in dojo/date/locale

it works perfectly if I put it in the js file, but, I do not want/cannot modify dojo's files.

I wanted to apply overriding solutions found here:

http://g00glen00b.be/dojo-inheritance-overriding-extending/ or here

without any success I get a SyntaxError: missing : after property id

on the line with var obj = new exports();

code from my last try:

require(["dojo/_base/lang", "dojo/date/locale"], function(lang, locale){
    lang.extend(locale, {
        var obj = new exports();
        obj._getWeekOfYear = function(/*Date*/ dateObject, /*Number*/ firstDayOfWeek){
            if(arguments.length == 1){ firstDayOfWeek = 0; }
            var determinedate = new Date();
            determinedate.setFullYear(dateObject.getFullYear(), dateObject.getMonth(), dateObject.getDate());
            var D = determinedate.getDay();
            if(D == firstDayOfWeek) D = 7;
            determinedate.setDate(determinedate.getDate() + (4 - D));
            var YN = determinedate.getFullYear();
            var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
            var WN = 1 + Math.floor(ZBDoCY / 7);
            return WN;
        };
    });
});

i tried :

exports._getWeekOfYear: function(...)    
exports._getWeekOfYear=: function(...)

Any ideas?

Upvotes: 0

Views: 1312

Answers (2)

kilicos
kilicos

Reputation: 99

thanks

i finally managed to do what i wanted with this code

require(["dojo/date/locale"], function( local){

        local._getWeekOfYear= function(/*Date*/ dateObject, /*Number*/ firstDayOfWeek){
            if(arguments.length == 1){ firstDayOfWeek = 0; }
            var determinedate = new Date();
            determinedate.setFullYear(dateObject.getFullYear(), dateObject.getMonth(), dateObject.getDate());
            var D = determinedate.getDay();
            if(D == firstDayOfWeek) D = 7;
            determinedate.setDate(determinedate.getDate() + (4 - D));
            var YN = determinedate.getFullYear();
            var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
            var WN = 1 + Math.floor(ZBDoCY / 7);
            return WN;
        }
    ;
});

indeed export was the pb.

Upvotes: 2

PaulR
PaulR

Reputation: 316

Without supplying the whole solution, the first thing that i notice is that "exports" is not a class which you can instantiate by using the new keyword. In that particular dojo module, exports is just an object which exposes the API.

Take a look at the solutions on SitePen, especially "MonkeyPatching" is a mechanism which works very well for me.

Upvotes: 2

Related Questions