Skip to content

Instantly share code, notes, and snippets.

@cScarlson
cScarlson / sample.08-06-2020.ts
Created June 8, 2020 18:50
The [Reusable] Chain of Responsibility Pattern (TypeScript)
class Handler {
respond(e: CustomEvent): any {
return e.detail; // continue and provide same value (see Function Purity)
}
}
/**
* @name: The Chain of Responsibility Pattern
* @intention
@lukehorvat
lukehorvat / es6-map-to-object-literal.js
Last active January 8, 2024 10:32
Convert ES6 Map to Object Literal
let map = new Map();
map.set("a", 1);
map.set("b", 2);
map.set("c", 3);
let obj = Array.from(map).reduce((obj, [key, value]) => (
Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.
), {});
console.log(obj); // => { a: 1, b: 2, c: 3 }
@cowboy
cowboy / call-invo-cursion.js
Last active March 30, 2023 01:59
JavaScript: call invo-cursion?
// OOP
console.log( 'OHAI'.blink() );
// Call invocation
console.log( String.prototype.blink.call('OHAI') );
// $ always makes things look awesome.
var $ = Function.prototype.call;
// Very explicit call invocation