Célia CACCIATORE
Jérémy BOSSUT
Jonathan GEOFFROY
15 Décembre 2014
var myObject = {};
myObject.sayHello(); // Error: undefined
myObject.sayHello = function () {
console.log("Hello World!");
}
myObject.sayHello(); // "Hello World!"
var intThree = 3;
var stringThree = "3";
intThree == stringThree; // true
intThree === stringThree; // false
var myParameterFunction = function() {
// Code to execute
}
myFunction(paramFunction) {
paramFunction();
}
// function given as a parameter of another
myFunction(myParameterFunction);
var animal = "I am a dog";
var transformToCat = function () {
animal = "I am a cat";
}
transformToCat();
console.log(animal); // "I am a cat"
var animal = "I am a dog";
var transformToCat = function () {
var animal = "Into function, I am a cat";
console.log(animal) // "Into function, I am a cat"
}
transformToCat();
console.log(animal); // "I am a dog"
Cache L1
Cache L2
RAM
Disque
Réseau
3 cycles
14 cycles
250 cycles
41 000 000 cycles
240 000 000 cycles
var processing = function (callback) {
// Processing
callback(result);
}
processing(function (res) {
console.log('processing ended!');
})
fs.readdir(source, function(err, files) {
files.forEach(function(filename, fileIndex) {
gm(source + filename).size(function(err, values) {
widths.forEach(function(width, widthIndex) {
this.resize(width, height).write(filename, function(err) {
if (err) console.log('Error writing file: ' + err)
});
}.bind(this))
});
});
});
var res = myFunction() {
// Processing
});
res.on('data', function (chunk) {});
res.on('error', function(e) {});
res.on('end', function(e) {});
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
// fichier myModule.js
myPrivateFunction : function() { ... }
module.exports {
myFunction : function() {
myPrivateFunction();
}
}
// fichier myApp.js
var myModule = require('./myModule.js');
myModule.myFunction();
$ npm install [-g] nomModule
$ npm install
var async = require('async');
// Process each item of array
async.each(array, function process(itemOfArray, asyncCallback) {
console.log('process: ' + itemOfArray);
asyncCallback();
});
},
// Callback called as soon as all files are processed
function () {
console.log('All files processed');
});
var fs = require('fs');
fs.readFile(file, function parse(err, data) {
console.log('file content: ' + data);
});
mkdir
chmod
createReadStream
var _ = require('underscore');
_.each(aMap, function (value, key) {
console.log(key + ' : ' + value);
}
_.map([1, 2, 3],
function(num) { return num * 3 ; });
// [3, 6, 9]
var evens = _.filter([1, 2, 3, 4, 5, 6],
function(num) { return num % 2 == 0; });
// [2, 4, 6]
url
port
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');