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.
15 Comments »
RSS feed for comments on this post. TrackBack URL
But this method prevents to write extensions for script.
When is the next Peppy release?
@Nosrenda: Unfortunately, it is later than I had originally planned. I will do my best to try to release it before the end of this year. Thanks.
Воздержусь…
Урааа… давно искал, спасибо большое
Воздержусь…
Отлично…
Статья помогла, спасибо!
Интересно, конечно! Спасибо! Прочитал с удовольствием и вниманием.
Хм, отличная статья
Хорошо пишете. Я бы конечно некоторые моменты оспорила, ну да ладно.
Thank you!
Вы занимаетесь сео на своем блоге? Я хочу заняться, но не знаю с чего начать… Я ваш сайт легко в поиске нашел, а моего блога там похоже и нету даже
Хороший у вас блог! А как вам мой? Я правда не по вашей теме пишу, а все больше про дачу свою на Старовенке, да про погребов обустройство, опытом делюсь. Так что если дачу строить затеяте - милости прошу ко мне на блог в комментарии с вопросами
Молодчинка, мне понравилось!