Skip to content

Instantly share code, notes, and snippets.

@voodootikigod
Created February 15, 2011 23:02
Show Gist options
  • Save voodootikigod/828469 to your computer and use it in GitHub Desktop.
Save voodootikigod/828469 to your computer and use it in GitHub Desktop.
function ClosurePattern() {
this.someMethod = function someMethod() {
console.log('foo');
}
}
var closurePattern = new ClosurePattern();
@creationix
Copy link

I wouldn't call this the closure pattern. It's just a really inefficient way to put functions on an object. Rather, I would do:

function ClosurePattern() {
  // Define some functions in the local scope
  function someMethod() {
    console.log('foo');
  } 
  // Export only what you want exposed using the closure
  return { someMethod: someMethod };
}
var closurePattern = ClosurePattern();

But, yeah, the same performance rules apply as the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment