background preloader

Docs

Facebook Twitter

Fonctions

Closures. Espaces de noms. Named function expressions demystified. Introduction Surprisingly, a topic of named function expressions doesn’t seem to be covered well enough on the web. 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. I’ll start with a general explanation of what function expressions are how modern debuggers handle them.

Function expressions vs. One of the two most common ways to create a function object in ECMAScript is by means of either Function Expression or Function Declaration. We can see that when identifier is omitted, that “something” can only be an expression. To demonstrate with examples: Getting Out of Binding Situations in JavaScript. Most developers don’t know about—or don’t care enough about—binding in JavaScript. Yet this single issue is responsible for a sizeable portion of the questions on most JavaScript-related support channels, and thousands—if not millions—of hairs being tortured away from developer heads every single day. Yet with a little attention to this oft-overlooked subject, you can avoid wasting your time, energy, and patience and move on to more powerful, efficient scripting.

Why should we care about binding? #section1 Almost no major object-oriented programming (OOP) languages force you to consider binding. PHP and JavaScript do require you to explicitly state which object you’re accessing, even if it’s the current one. Of course, neither PHP nor JavaScript are actually object-oriented in the traditional sense. In JavaScript, binding is always explicit, and can easily be lost, so a method using this will not refer to the proper object in all situations, unless you force it to. Okay, that’s weird.

Objets

Portée des variables. Learn to code. Les bases du Javascript. JavaScript: la référence - David Flanagan. Bonnes pratiques javascript.