W.l.o.g we assume that all native cancellable activities are exposed to the JavasScript in the following form:
function doIt(
options: any,
cb: (error: any, result: ResultType) => void
): CancellationHandle {
[native code]
}
* JavaScript | |
functions and prototypes, | |
closures, | |
modelling of classes | |
ES6: Map, Set, WeakMap, Symbol, Promise, structuring/destructuring | |
Babel. ES7: Observable, bind, spread/rest | |
Playground | |
* Goals and Non-Goals | |
* Basic Types |
W.l.o.g we assume that all native cancellable activities are exposed to the JavasScript in the following form:
function doIt(
options: any,
cb: (error: any, result: ResultType) => void
): CancellationHandle {
[native code]
}
Here is an example how await
operator can be desugared into Promise-based code without ES6 generators (and state machines that emulate generators missing in ES5).
The only assumption is that there is Promise.resolve
(to create an empty promise for the loop finalization) among the globals.
Examples are written with "throw early" policy adoption: if promisified code has a synchronous preamble that throws we prefer to throw instead of creating rejected Promise.
Note that patterns below don't cover control flow breaks like return
, break
, continue
and throw
(for these breaks we should use a bit more complex structures).
someFunc = (x,y,z, cb) -> | |
await check x, defer err, res_x | |
return cb err if err | |
await check x, defer err, res_y | |
return cb err if err | |
await check x, defer err, res_z | |
return cb err if err | |
cb null, res_x + res_y + res_z | |
Эта статья предназначена для тех, кому волею судеб нужно разбирать большие XML-файлы, но той же волею им доступно это делать на JavaScript или [CoffeeScript] на [NodeJS]. Речь пойдёт об использовании npm-пакета [xml-stream], основными свойствами которого являются: