2

I am working with a language file that stores the traductions for the jquery datepicker URL: http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/i18n/jquery-ui-i18n.min.js?ver=3.4.2

The jQuery.datepicker.regional object is returned and I would like to access the it (italian) property of this object. My problem is that when I do something like

console.log(jQuery.datepicker.regional['it'])

or

console.log(jQuery.datepicker.regional.it)

the console says the object is undefined.

But when I do something like:

    console.log(jQuery.datepicker.regional);

The console returns something like this:

[Object]
    : Object
    af: Object
    ar: Object
    ...
    it: Object

What am I doing wrong? The "it" object is there isn't it? How can I access the "it" object of the jQuery.datepicker.regional object?

Thanks

Vincent
  • 1,651
  • 9
  • 28
  • 54

2 Answers2

5

jQuery.datepicker.regional is updated with each translation object when the DOM is ready:

JQuery(function($){ 
    $.datepicker.regional['it'] = {
        // …
    }
})

Try accessing it similarly:

$(function() {
    console.log(jQuery.datepicker.regional.it)
})

Aside regarding console.log

console.logging just the regional object shows all the localization objects because console.log (and sometimes console.dir) prints a reference to the object, whose properties may have changed by the time you actually look at them in the console. There are definitely some browser idiosyncrasies.

For example, in Chrome 25.0.1337.0:

var foo = {};
console.dir(foo) // Object: { baz: "bip" }

console.log(foo) // Object: {}
console.log(foo.baz); // undefined

foo.baz = "bip";


var bar = {};
console.dir(bar) // Object: { baz : { foo: 10 }}

bar.prototype = new Array;
console.log(bar) // Object: { baz : { foo: 10 }}
console.log(bar.baz); // undefined

bar.baz = { foo: 10 };

While in Firefox 17.0 + Firebug 1.9.2:

var foo = {};
console.dir(foo) // Object: { }

console.log(foo) // Object: { baz: "bip" }
console.log(foo.baz); // undefined

foo.baz = "bip";


var bar = {};
console.dir(bar) // Object: {}

bar.prototype = new Array;
console.log(bar) // Object: { baz : { foo: 10 }}
console.log(bar.baz); // undefined

bar.baz = { foo: 10 };
Community
  • 1
  • 1
eager
  • 627
  • 6
  • 10
2

Try this:

var regional = jQuery.datepicker.regional;
console.log(regional.it); 
console.log(regional['it']); 
SM79
  • 1,234
  • 2
  • 15
  • 33