Skip to content

Instantly share code, notes, and snippets.

@kareniel
kareniel / remote.js
Created April 8, 2016 14:38
Calls a function based on the value it receives.
function remote(action) {
const actions = { open, close, reset }[action]()
function open() { console.log('opened') }
function close() { console.log('closed') }
function reset() { console.log('reset') }
}
remote('open') // 'opened'
@kareniel
kareniel / deathBy_inception.js
Last active April 7, 2016 01:47
How to lose a value within a recursive function.
let tree = {
name: "A",
parent: {
name: "B",
parent: {
name: "C",
parent: {
name: ""
}
}
@kareniel
kareniel / debounce.js
Last active February 21, 2016 06:59
throttle function, that fires a message every 250ms by default (rather than at the end of a burst of events).
function throttle(fn, threshhold, scope) {
threshhold || (threshhold = 250);
var last,
deferTimer;
return function () {
var context = scope || this;
var now = +new Date,
args = arguments;
if (last && now < last + threshhold) {