Peppy, closures and patterns
Hi Folks,
I have been traveling so sorry it’s been a while since the last post.
JavaScript is a really cool language. One of my favorite aspects of JavaScript is closures. When designing a reusable piece of work, using closures is a great way to restrict pollution of the global scope.
You may have noticed that Peppy is wrapped in an anonymous function that executes immediately. Inside of this anonymous function I set only two global variables: “peppy” and “$” (”$” is only set if it doesn’t already exist). Everything else is wrapped up inside of a closure.
There are many useful patterns involving closures and one of them that you may have heard of is the Module pattern. If I were to write peppy using this pattern it would look something like this:
I chose not to use this pattern though because Peppy handles some follow up initialization stuff that needs to occur after the definition of Peppy and it just didn’t quite fit as cleanly within the module pattern.
Well that’s it for this post, I just wanted to write a quick one as I have been hard at work on putting together some documentation for Peppy as well as working on the next release.