I'm writing an API and I need to execute a ternary inside a "getter" function for various fields. This works fine but I don't want the end user to have to use parentheses when accessing these fields.
Strangely the getter code actually executes when I access the field without the parentheses but I'm wondering if this is normal for javascript or if this is browser dependent? Currently using Firefox 31.
This works:
var theScript = Scripts.jQuery_1_11_1_js(); // Note I'm using the parentheses
This also works even without parentheses. How?:
var theScript = Scripts.jQuery_1_11_1_js; // Note the lack of parentheses
Example API:
var Scripts = (function () {
function Scripts() {
}
Scripts.isProduction = false;
Scripts.Url = "/Scripts";
Scripts.jQuery_1_11_1_js = function () {
return Scripts.isProduction ? Scripts.Url + "/jQuery_1_11_1.min.js" : Scripts.Url + "/jQuery_1_11_1.js";
}
return Scripts;
})();
var theScript = Scripts.jQuery_1_11_1_js();
var theScript = Scripts.jQuery_1_11_1_js; /// why does this work?