Skip to content

Instantly share code, notes, and snippets.

* 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
@Artazor
Artazor / cancel.md
Last active August 29, 2015 14:16
Cancellation semantics

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]
}
@Artazor
Artazor / await-promises.md
Last active July 25, 2023 11:44
Await operator desugaring into promises

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).

Asynchronous sequence

@Artazor
Artazor / Unwinds.iced
Created November 5, 2013 16:05
Any chances to make such syntax/semantics consistent? Can we allow multiple unwinds 1) per defer 2) dynamically per await (eg in await for-loops) 3) statically per await
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
@Artazor
Artazor / xml-stream.ru.md
Created June 26, 2011 12:15
Потоковый разбор и редактирование XML средствами JavaScript

Потоковый разбор и редактирование XML средствами JavaScript

Коротко

Эта статья предназначена для тех, кому волею судеб нужно разбирать большие XML-файлы, но той же волею им доступно это делать на JavaScript или [CoffeeScript] на [NodeJS]. Речь пойдёт об использовании npm-пакета [xml-stream], основными свойствами которого являются:

  • Событийный разбор XML на более высоком уровне абстракции чем в случае с SAX-образным парсером.
  • Представление избранных участков XML в виде чистых объектных моделей (обычные объекты JavaScript) для редактирования и анализа (подобных SimpleXML в PHP) и сообщение о них в виде событий.