Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript The Module Pattern in JavaScript

Raphaël Seguin
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Raphaël Seguin
Full Stack JavaScript Techdegree Graduate 29,228 Points

Should'n't we NOT declare again the exports object in the loose augmentation pattern example code ?

Hi all, If you do so, the awesomeNewModule is simply re-initialized... or am I missing the whole thing ? I've rewritten the example so it would work for me.

var someModule =  {
  baba: 8
}

var someModule = (function(augmentMe) {
  augmentMe.bibi = 4;

  augmentMe.bonjour = function() {
    console.log("bonjour");
  }
  return augmentMe;
}(someModule || {}));

someModule.bonjour();
console.log(someModule.baba, someModule.bibi);

I'm surprised to be the first to ask, so please tell me if got something wrong. Thanks.

Tim Gavlick
Tim Gavlick
11,725 Points

I believe you're correct. Reassigning exports to a new object literal seems like it would overwrite any previous properties of that object if it already exists.