Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments regarding The Module Pattern #175

Open
svenheden opened this issue Aug 2, 2015 · 1 comment
Open

Comments regarding The Module Pattern #175

svenheden opened this issue Aug 2, 2015 · 1 comment
Labels

Comments

@svenheden
Copy link
Contributor

First of all I want to thank you for writing a great book! I'm reading it right now and found a couple of minor semantic issues in the chapter The Module Pattern.

  1. The pattern is quite similar to an immediately-invoked functional expression (IIFE - see the section on namespacing patterns for more on this) except that an object is returned rather than a function.

    I don't think the module pattern is similar to an IIFE; it uses an IIFE. And in an IIFE a function isn't necessarily returned, it's invoked. Don't you agree? :)

  2. Other disadvantages [in The Module Pattern] include the inability to create automated unit tests for private members and additional complexity when bugs require hot fixes. It's simply not possible to patch privates. Instead, one must override all public methods which interact with the buggy privates.

    Isn't this more of a problem with encapsulation (with private members) per se rather than with The Module Pattern?

    One could also argue that this is not a disadvantage at all. Private methods are by definition implementation details and should not be unit tested directly. But I guess this is debatable, but still; I don't think this is a problem with the pattern, I think it's part of the nature of private members.

I'm gonna continue to enjoy the book now and I hope you don't mind me submitting besserwisser issues like this! ;)

@svenheden svenheden changed the title Minor correction regarding IIFE Comments regarding The Module Pattern Aug 2, 2015
@addyosmani addyosmani added the bug label Jul 29, 2017
@addyosmani
Copy link
Owner

I don't think the module pattern is similar to an IIFE; it uses an IIFE. And in an IIFE a function isn't necessarily returned, it's invoked. Don't you agree? :)

I agree @JonathanP. Master should now reflect this error in the way I originally described it :)

Isn't this more of a problem with encapsulation (with private members) per se rather than with The Module Pattern?

Coming back to this pattern a few years later, you're pretty right. This is more of a fundamental problem around encapsulation in JS than the module pattern itself. I wonder if there's a way we can better word this section.

The current book doesn't dive into any of the nuance around ES2015+ and more recent thinking about privacy in JS (WeakMaps, private/public class fields etc), although I think that might need to wait for a larger refresh of the book. Is there a good way you could see us rephrasing that paragraph? A PR would be welcome or we could iterate on wording here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants