0

In java script I get this error

Uncaught ReferenceError: baseUrl is not defined 



window.Configurations = Configurations = {
        baseUrl: 'https://mysite.com/',
        detailsEventCustom: baseUrl + 'DetailsEventCustom?EventId=',
        addEventCustom: baseUrl + 'AddEventCustom',
        listAllEventsCustomForDate: baseUrl + 'ListAllEventsCustomForDate?DateToLookUp=',
        dashboardEventsCustom: baseUrl + 'DashboardEventsCustom',
        listAllTimetableEventsCustom: baseUrl + 'ListAllTimetableEventsCustom',
        updateEventCustom: baseUrl + 'UpdateEventCustom?EventId=',
        deleteEventCustom: baseUrl + 'DeleteEventCustom?EventId='
    };

Could you point me out what I am doing wrong here?

GibboK
  • 71,848
  • 143
  • 435
  • 658
  • There is no `baseUrl` variable. And the property of your object can't be used before it is constructed. – Bergi Feb 05 '13 at 07:56
  • exact duplicate of [Self-references in object literal declarations](http://stackoverflow.com/questions/4616202/self-references-in-object-literal-declarations) – Bergi Feb 05 '13 at 07:58
  • Thanks Bergi for pointing out that post – GibboK Feb 05 '13 at 09:31

2 Answers2

2

you cannot do it like this
when you are accessing the object hasn't been made try doing this instead

var baseUrl = 'https://mysite.com/';
window.Configurations = Configurations = {
        baseUrl: baseUrl,
        detailsEventCustom: baseUrl + 'DetailsEventCustom?EventId=',
        addEventCustom: baseUrl + 'AddEventCustom',
        listAllEventsCustomForDate: baseUrl + 'ListAllEventsCustomForDate?DateToLookUp=',
        dashboardEventsCustom: baseUrl + 'DashboardEventsCustom',
        listAllTimetableEventsCustom: baseUrl + 'ListAllTimetableEventsCustom',
        updateEventCustom: baseUrl + 'UpdateEventCustom?EventId=',
        deleteEventCustom: baseUrl + 'DeleteEventCustom?EventId='
    };
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
0

This is a scoping problem. You are still building the object between the curly braces, and all values are calculated before they are assigned to the object. baseUrl simply doesn't exist yet when you are using it to assign the other values. You should do something like this instead:

var baseUrl = 'https://mysite.com/'
window.Configurations = Configurations = {
    baseUrl: baseUrl,
    detailsEventCustom: baseUrl + 'DetailsEventCustom?EventId=',
    addEventCustom: baseUrl + 'AddEventCustom',
    listAllEventsCustomForDate: baseUrl + 'ListAllEventsCustomForDate?DateToLookUp=',
    dashboardEventsCustom: baseUrl + 'DashboardEventsCustom',
    listAllTimetableEventsCustom: baseUrl + 'ListAllTimetableEventsCustom',
    updateEventCustom: baseUrl + 'UpdateEventCustom?EventId=',
    deleteEventCustom: baseUrl + 'DeleteEventCustom?EventId='
};
rtytgat
  • 488
  • 2
  • 10