Archiv der Kategorie ‘javascript‘


ES6 Mode Mouse Event Manager

let ui = {
  ['draw-poly-mousedown'](e) {
    console.log('draw poly mouse down');
  ['draw-poly-mouseup'](e) {
    console.log('draw poly mouse up');
  execMode(e) {
    let fn = ui[`${ui.mode}-${e.type}`];
    if (fn) fn(e);
ui.mode = 'draw-poly';

let e = {};
e.mousedown = 
e.mouseup = 
e.mousemove = (e) => ui.execMode(e);

XOR Color Invert

var color = 0xFFFF00;

function toHex(color) { 
  return '#' + ('000000' + color.toString(16)).substr(-6);

function onClick() {
  color ^= 0xFFFFFF; = toHex(color);


document.addEventListener('click', onClick);

Have a look at the slighty different ES6 version:

This is a great trick and a good reason to learn XOR and binary if you don’t already know about those things. The `toHex` function is also kind of snippet worthy in itself.

Quick Alphabet Array

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');

console.log('this is the letter b...', alphabet[1]);

The above will output:

this is the letter b... b
["a", "b", "c", "d", "e"...']

In ES6 you could use `let` instead of `var`.

The UKGC also plans to introduce a new licensing operations model. Instead of assigning a single account manager to each operator, the new system will assign separate representatives to each subgroup to handle different forms of licensing. The new system will have four sub-groups that will focus on different stages of the process. This new system will also help UKGC operate more efficiently. Further, the UKGC intends to increase transparency in the licensing process.