0
Accessing an object with a square object syntax
var roomsFree = hotel['checkAvailability'](); The checkAvailability is a property of an object that contains a function. So why does the () on the above statement outside the square bracket syntax and the single quotes? Shouldn't the () be with the 'checkAvailability' property?
1 Respuesta
+ 1
Think about it this way. hotel.checkAvailability is equivalent to hotel['checkAvailibility'] in that it is a reference to the function. To execute it, you add the parens. You are executing the reference, so you append the parens after the reference has been defined. The 'checkAvailability' is simply the key youre looking up, it wouldnt make sense to add the invocation parens to they key.