background preloader

JS

Facebook Twitter

GitHub - adam-s/js-interview-review: The JS interview review. As I'm reviewing several resources I've bookmarked on JavaScript development, I'll share them here. Skilldrick » Closures explained with JavaScript. Last year I wrote A brief introduction to closures which was meant to help people understand exactly what a closure is and how it works.

Skilldrick » Closures explained with JavaScript

I’m going to attempt that again, but from a different angle. I think with these kinds of concept, you just need to read as many alternative explanations as you can in order to get a well rounded view. First-class functions As I explained in Why JavaScript is AWESOME, one of the most powerful parts of JavaScript is its first-class functions. So, what does “first-class” mean in a programming language? Can be stored in variables and data structures can be passed as a parameter to a subroutine can be returned as the result of a subroutine can be constructed at runtime has intrinsic identity (independent of any given name) So, functions in JavaScript are just like objects.

The ability to nest functions gives us closures. ECMA-262-3 in detail. Chapter 5. Functions. Read this article in: Russian, Chinese (version 1, version 2), French.

ECMA-262-3 in detail. Chapter 5. Functions.

In this article we will talk about one of the general ECMAScript objects — about functions. In particular, we will go through various types of functions, will define how each type influences variables object of a context and what is contained in the scope chain of each function. We will answer the frequently asked questions such as: “is there any difference (and if there are, what are they?) Between functions created as follows: from functions defined in a “habitual” way?” Or, “why in the next call, the function has to be surrounded with parentheses?” Since these articles relay on earlier chapters, for full understanding of this part it is desirable to read Chatper 2.

But let us give one after another. In ECMAScript there are three function types and each of them has its own features. JS. The Best Module System for AngularJS Applications. I was working on a small and simple application built with AngularJS the other day.

The Best Module System for AngularJS Applications

As with most applications like this, I start with a single JavaScript file called app.js and no module system. In the past, I've used RequireJS with AngularJS. It's an awful mistake. It leads to a big jump in complexity with no benefits. Angular apps don't work well with AMDs, so really you are using RequireJS to combine files into one big file. Mastering the Module Pattern. I'm a massive fan of JavaScript's Module Pattern and I'd like to share some use cases and differences in the pattern, and why they're important.

Mastering the Module Pattern

The Module Pattern is what we'd call a "design pattern", and it's extremely useful for a vast amount of reasons. My main attraction to the Module Pattern (and it's variant, the Revealing Module Pattern) are because it makes scoping a breeze, and doesn't overcomplicate JavaScript design. Named function expressions demystified. Introduction Surprisingly, a topic of named function expressions doesn’t seem to be covered well enough on the web.

Named function expressions demystified

This is probably why there are so many misconceptions floating around. In this article, I’ll try to summarize both — theoretical and practical aspects of these wonderful Javascript constructs; the good, bad and ugly parts of them. In a nutshell, named function expressions are useful for one thing only — descriptive function names in debuggers and profilers. Well, there is also a possibility of using function names for recursion, but you will soon see that this is often impractical nowadays.

JavaScript Promises: There and back again. Ladies and gentlemen, prepare yourself for a pivotal moment in the history of web development… [Drumroll begins] Promises have arrived natively in JavaScript! [Fireworks explode, glittery paper rains from above, the crowd goes wild] At this point you fall into one of these categories: People are cheering around you, but you're not sure what all the fuss is about.

Generators in Node.js: Common Misconceptions and Three Good Use Cases. Generators have been all the rage lately.

Generators in Node.js: Common Misconceptions and Three Good Use Cases

Many Node developers (including myself!) Are excited and intrigued about writing their asynchronous code like this: Kriskowal/q. Immediately-Invoked Function Expression (IIFE) In case you hadn’t noticed, I’m a bit of a stickler for terminology.

Immediately-Invoked Function Expression (IIFE)

So, after hearing the popular, yet misleading, JavaScript term “self-executing anonymous function” (or self-invoked anonymous function) one too many times, I’ve finally decided to organize my thoughts into an article. In addition to providing some very thorough information about how this pattern actually works, I’ve actually made a recommendation on what we should call it, moving forward.

Also, If you want to skip ahead, you can just check out some actual Immediately-Invoked Function Expressions, but I recommend reading the entire article. Please understand that this article isn’t intended to be an “I’m right, you’re wrong” kind of thing. I’m genuinely interested in helping people understand potentially complex concepts, and feel that using consistent and accurate terminology is one of the easiest things that people can do to facilitate understanding.

So, what’s this all about, anyways? The heart of the matter.