background preloader

Language (javaScript JS)

Facebook Twitter

Pr/src/OReilly_JavaScript_The_Good_Parts_May_2008.pdf.

Js.doc

Javascript and design pattern. JavaScript tutorial: Variable scope and the var keyword. Simple example with comments: <html><head><script type="text/javascript" language="JavaScript"><! -- var numberCars = 3; // global numberTrees = 15; // global if (numberTrees > numberCars) { var numberRoads = 4; // global } else { var numberLakes = 9; // global, but will be undefined since never get in here. } function simpleFunction() { var colorCar = 'blue'; // local colorTree = 'green'; // global, once this function is called if (colorCar ! = colorTree) { var colorRoad = 'grey'; // local anywhere in this function after this line } else { var colorLake = 'aqua'; // local, but will be undefined since never get in here. } } //--></script></head><body></body></html> Detailed example that writes to this page: You can reference all local variables inside the same function the variables are declared.

You can reference all global variables inside any function. Outside a function, you can only reference local variables that are not declared with the var keyword. Formation JavaScript - Table des matières. Javascript - Le mot-clé this. JavaScript Guide. Closures. Closures are functions that refer to independent (free) variables.

Closures

In other words, the function defined in the closure 'remembers' the environment in which it was created in. Consider the following: function init() { var name = "Mozilla"; function displayName() { alert (name); } displayName(); }init(); init() creates a local variable name and then a function called displayName(). displayName() is the inner function (a closure) — it is defined inside init(), and only available within the body of that function . Unlike init(), displayName() has no local variables of its own, and instead reuses the variable name declared in the parent function. Run the code and see that this works. Now consider the following example: Details of the object model (Class-based vs. prototype-based languages) The content of this article is under discussion.

Details of the object model (Class-based vs. prototype-based languages)

Please provide feedback and help us to make this page better: bug 1201380. JavaScript is an object-based language based on prototypes, rather than being class-based. Because of this different basis, it can be less apparent how JavaScript allows you to create hierarchies of objects and to have inheritance of properties and their values. This chapter attempts to clarify the situation. This chapter assumes that you are already somewhat familiar with JavaScript and that you have used JavaScript functions to create simple objects. Class-based vs. prototype-based languagesEdit Class-based object-oriented languages, such as Java and C++, are founded on the concept of two distinct entities: classes and instances.

A class defines all of the properties (considering methods and fields in Java, or members in C++, to be properties) that characterize a certain set of objects.

Closures (Javascript)

String (javascript) What does ':' do in JavaScript. Static variables in JavaScript. Const, let et var / la déclaration de variables / ES6, ES2015. Promise.prototype.then() - JavaScript. The then() method returns a Promise.

Promise.prototype.then() - JavaScript

It takes up to two arguments: callback functions for the success and failure cases of the Promise. The source for this interactive demo is stored in a GitHub repository. If you'd like to contribute to the interactive demo project, please clone and send us a pull request. If one or both arguments are omitted or are provided non-functions, then then will be missing the handler(s), but will not generate any errors. If the Promise that then is called on adopts a state (fulfillment or rejection) for which then has no handler, a new Promise is created with no additional handlers, simply adopting the final state of the original Promise on which then was called.

Syntax. Promise.prototype.then() - JavaScript. La méthode then() renvoie un objet Promise.

Promise.prototype.then() - JavaScript

Elle peut prendre jusqu'à deux arguments qui sont deux fonctions callback à utiliser en cas de complétion ou d'échec de la Promise. Le code source de cet exemple interactif est disponible dans un dépôt GitHub. Si vous souhaitez contribuez à ces exemples, n'hésitez pas à cloner et à envoyer une pull request ! Note : Si aucun des deux arguments n'est utilisé ou que les objets fournis ne sont pas des fonctions, une nouvelle promesse est créée sans autre gestionnaire supplémentaire. What does the function then() mean in JavaScript? Javascript - What is "callback hell" and how and why RX solves it?

Javascript - Understanding the Event Loop. Javascript callback functions tutorial. Async function - JavaScript. The async function declaration defines an asynchronous function, which returns an AsyncFunction object.

async function - JavaScript

The source for this interactive demo is stored in a GitHub repository. If you'd like to contribute to the interactive demo project, please clone and send us a pull request. Syntax async function name([param[, param[, ... param]]]) { statements } Parameters name The function name. param The name of an argument to be passed to the function. statements The statements comprising the body of the function. Return value An AsyncFunction object, representing an asynchronous function which executes the code contained within the function.

Description When an async function is called, it returns a Promise. An async function can contain an await expression, that pauses the execution of the async function and waits for the passed Promise's resolution, and then resumes the async function's execution and returns the resolved value. Async/await. There’s a special syntax to work with promises in a more comfortable fashion, called “async/await”. It’s surprisingly easy to understand and use. Object.prototype.constructor - JavaScript. JavaScript Constructors. Constructor - JavaScript. La méthode constructor est une méthode qui est utilisée pour créer et initialiser un objet lorsqu'on utilise le mot clé class.

constructor - JavaScript

Le code source de cet exemple interactif est disponible dans un dépôt GitHub. Si vous souhaitez contribuez à ces exemples, n'hésitez pas à cloner et à envoyer une pull request ! Syntaxe. Async Javascript Introduction - Callbacks, Async/Await, Promises. Apprendre le JavaScript : Chapitre 7, Portée des variables & Hoisting. Apprendre le JavaScript : Chapitre 8, L'opérateur this. Apprendre le JavaScript : Chapitre 9, Les prototypes. Apprendre le JavaScript : Chapitre 11, L'objet Window. Apprendre le JavaScript : Chapitre 12, Le DOM.