A question from curiosity. I analyze some Ember app for the first time and I met such a code:
export default Service.extend({
api: service(),
router: service(),
flashes: service(),
intercom: service(),
store: service()
// ...
})
As I can see, the service function here is clever enough to return adequate results for every key it is called at. And my question is: how is it possible? I thought that I know JavaScript, but I have no idea how it could be implemented. JavaScript functions know only their arguments and this object they are called for, don't they?
As far as I can tell from the API docs and from the source this is able to work because you're calling service() on a special type of object which has what Ember calls an 'owner'. When the service gets called it can use the objects owner to lookup the name of the property and determine the name of the service. I might be reading this wrong, I'm like 50% confident.