Nov
08
2008

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:

peppy = function() {
// private data
return { query: function…
}
}();

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.

Written by jdonaghue in: JavaScript, Peppy |

15 Comments »

  • But this method prevents to write extensions for script.

    Comment | November 10, 2008
  • When is the next Peppy release?

    Comment | December 1, 2008
  • jdonaghue

    @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.

    Comment | December 3, 2008
  • Воздержусь…

    Comment | December 17, 2008
  • Урааа… давно искал, спасибо большое ;)

    Comment | December 18, 2008
  • Воздержусь…

    Comment | December 18, 2008
  • Отлично…

    Comment | December 19, 2008
  • Статья помогла, спасибо!

    Comment | December 19, 2008
  • Интересно, конечно! Спасибо! Прочитал с удовольствием и вниманием.

    Comment | December 19, 2008
  • Хм, отличная статья ;)

    Comment | December 19, 2008
  • Хорошо пишете. Я бы конечно некоторые моменты оспорила, ну да ладно.

    Comment | December 22, 2008
  • Thank you!

    Comment | January 10, 2009
  • Вы занимаетесь сео на своем блоге? Я хочу заняться, но не знаю с чего начать… Я ваш сайт легко в поиске нашел, а моего блога там похоже и нету даже :(

    Comment | January 19, 2009
  • Хороший у вас блог! А как вам мой? Я правда не по вашей теме пишу, а все больше про дачу свою на Старовенке, да про погребов обустройство, опытом делюсь. Так что если дачу строить затеяте - милости прошу ко мне на блог в комментарии с вопросами ;)

    Comment | January 20, 2009
  • Молодчинка, мне понравилось!

    Comment | January 25, 2009

RSS feed for comments on this post. TrackBack URL

Leave a comment

Comments require approval, so they will not display immediately.

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes