Skip to main content
added 80 characters in body
Source Link
Shai
  • 7.4k
  • 3
  • 21
  • 22

ThoseBecause those three inner functions (publish, subscribe and unsubscribe) are declared inside an outeranother function: they would not, by default, they wouldn't exist anywhere except locally inside theanywhere outside that outer anonymous function in which they were declared.

By returning that { ... } object with those three properties, you are effectively offering a 'public' API into the messageBusmessageBus will beequal an object with properties of those 3 functions that, so they can be called from the outer scope.

If the object wasn't returned, there would be no way to call those three inner functions from anywhere in the outer scope.

Those three inner functions (publish, subscribe and unsubscribe) are declared inside an outer function: they would not, by default, exist anywhere except locally inside the outer anonymous function in which they were declared.

By returning that { ... } object with those three properties, you are effectively offering a 'public' API into the messageBusmessageBus will be an object with 3 functions that can be called from the outer scope.

Because those three inner functions (publish, subscribe and unsubscribe) are declared inside another function, they wouldn't exist anywhere outside that outer function.

By returning that { ... } object with those three properties, you are effectively offering a 'public' API into the messageBusmessageBus will equal an object with properties of those 3 functions, so they can be called from the outer scope.

If the object wasn't returned, there would be no way to call those three inner functions from anywhere in the outer scope.

Source Link
Shai
  • 7.4k
  • 3
  • 21
  • 22

Those three inner functions (publish, subscribe and unsubscribe) are declared inside an outer function: they would not, by default, exist anywhere except locally inside the outer anonymous function in which they were declared.

By returning that { ... } object with those three properties, you are effectively offering a 'public' API into the messageBusmessageBus will be an object with 3 functions that can be called from the outer scope.