Skip to main content

Posts

Showing posts from July, 2011

Express (JS, of course)

Q: What's ExpressJS? A: quite possibly the coolest thing to happen to Node.JS... EVAR!  This is awesome news for web developers and programmers. OK, you're interested now.  So, if you've followed my blog recently, you know that JavaScript is pure awesomeness.  You also know that server-side JavaScript is the way of the future.  Node.JS is the server-side JavaScript environment.  ExpressJS is the library. Q: So, what do you currently do to write web applications and web services? A: I write PHP code that runs on an Apache web server (or Lighttpd-FastCGI if you prefer).  The PHP code does cool stuff like session handling, parsing URL-encoded POST responses, talking to a database (probably MySQL), generating HTML, etc.  I use HTML, CSS, and JavaScript for the client-side stuff. Q: What do you REALLY want to do? A: Uhhh.... write awesome JavaScript code??? YES!  That's exactly right! You don't need PHP anymore! (Wha???)  You don't even need Apache/Light

JavaScript Closures

What are closures in JavaScript? Taken from  http://jibbering.com/faq/notes/closures/ : The simple explanation of a Closure is that ECMAScript allows inner functions; function definitions and function expressions that are inside the function bodes of other functions. And that those inner functions are allowed access to all of the local variables, parameters and declared inner functions within their outer function(s). A closure is formed when one of those inner functions is made accessible outside of the function in which it was contained, so that it may be executed after the outer function has returned. At which point it still has access to the local variables, parameters and inner function declarations of its outer function. Those local variables, parameter and function declarations (initially) have the values that they had when the outer function returned and may be interacted with by the inner function. For Example: var x; function foo() {     var i = 2;     function bar()