Javascript

Simple promise with async / await

Script const simple_promise_demo = (a, b) => { return new Promise((resolve, reject) => { if (b !== 0) { resolve(a / b); } else { let problem = new Error(a + " / " + b + " -> Cant divide by zero!"); reject(problem); } }); }; const...

Simple promise

Function const simple_promise_demo = (a, b) => { return new Promise((resolve, reject) => { if (b !== 0) { resolve(a / b); } else { let problem = new Error(a + " / " + b + " -> Cant divide by zero!"); reject(problem); } }); }; Ex...

Moduel Pattern

Create a simple module var MODULE = (function (module) { sayHello = function () { console.log("Hello world"); }; // public bindings module.sayHello = sayHello; return module; })(MODULE || {}); Implement a sub module var MODULE = (function (module) { var sub = (...

Build a dynamic regex with a variable

I needed to build a dynamic regex, which consists of a variable. var decimal_separator = "."; var regex = new RegExp("[0-9]|\\" + decimal_separator);