Efficaces mais requièrent un préprocesseur
class Greeter {
constructor(public greeting: string) { }
greet() {
return "" + this.greeting + "
";
}
};
var greeter = new Greeter("Hello, world!");
document.body.innerHTML = greeter.greet();
function foo(finalCallback) {
request.get(url1, function(err1, res1) {
if (err1) { return finalCallback(err1); }
request.post(url2, function(err2, res2) {
if (err2) { return finalCallback(err2); }
request.put(url3, function(err3, res3) {
if (err3) { return finalCallback(err3); }
request.del(url4, function(err4, res4) {
// let's stop here
if (err4) { return finalCallback(err4); }
finalCallback(null, "whew all done");
})
})
})
})
}
function foo() {
return request.getAsync(url1)
.then(function(res1) {
return request.postAsync(url2);
}).then(function(res2) {
return request.putAsync(url3);
}).then(function(res3) {
return request.delAsync(url4);
}).then(function(res4) {
return "whew all done";
});
}
async function foo() {
var res1 = await request.getAsync(url1);
var res2 = await request.getAsync(url2);
var res3 = await request.getAsync(url3);
var res4 = await request.getAsync(url4);
return "whew all done";
}
function MyObjectA () {}
MyObjectA.prototype = {
myMethod: function () {}
};
var obj = new MyObjectA();
class MyObjectC {
myMethod () {
}
}
var obj = new MyObjectC();
function fn() {
let foo = "bar";
var foo2 = "bar";
if (true) {
let foo; // pas d'erreur, foo === undefined
var foo2; // foo2 est en réalité écrasé !
foo = "qux";
foo2 = "qux";
console.log(foo); // "qux"
console.log(foo2); // "qux"
}
console.log(foo);// "bar"
console.log(foo2); // "qux"
}
const myModule = require("./my-module.js")
// main.js
const worker = new Worker('worker.js');
// To be shared
const sharedBuffer = new SharedArrayBuffer( // (A)
10 * Int32Array.BYTES_PER_ELEMENT); // 10 elements
// Share sharedBuffer with the worker
worker.postMessage({sharedBuffer}); // clone
// Local only
const sharedArray = new Int32Array(sharedBuffer); // (B)
// Initialization before sharing the Array
Atomics.store(sharedArray, 0, 1);
// main.js
Atomics.store(sharedArray, 0, 2);
// worker.js
while (Atomics.load(sharedArray, 0) === 1) ;
console.log(Atomics.load(sharedArray, 0)); // 2
function compiledCalculation() {
var x = f()|0; // x is a 32-bit value
var y = g()|0; // so is y
return (x+y)|0; // 32-bit addition, no type or overflow checks
}