Skip to content

Instantly share code, notes, and snippets.

@livingston
livingston / ES5 Extend & Clone Objects.js
Created February 1, 2011 10:00
ES5 Extend & Clone Objects
Object.defineProperties(Object, {
'extend': {
'configurable': true,
'enumerable': false,
'value': function extend(what, wit) {
var extObj, witKeys = Object.keys(wit);
extObj = Object.keys(what).length ? Object.clone(what) : {};
witKeys.forEach(function (key) {
var flatten = (a, r, cb) => {
if (typeof a.length === 'undefined') {
r.push(a);
return cb;
} else if (a.length === 0) {
return cb;
} else {
return flatten(a[0], r, () => flatten(a.slice(1), r, cb));
}
};

Comparison of Typescript and Flow

Common Features

  • Lots of type inference

  • Null/undefined checking

Similar syntax
@slikts
slikts / fizzBuzz.js
Last active December 5, 2018 11:33
Enterprise edition
const Range = (a, b) => Array.from({ length: b - a }, (_, i) => a + i)
const NumTest = (n, text) => k => !(k % n) ? text : ''
const Tests = data => Object.entries(data).map(([n, text]) => NumTest(n, text))
const RangeTest = tests => n => tests.map(fn => fn(n)).join('') || n
const RangeMap = (a, b, tests) => Range(a, b).map(RangeTest(tests))
const fizzBuzz = (a, b) => RangeMap(a, b, Tests({
5: 'Fizz',
3: 'Buzz',
}))
@rwaldron
rwaldron / array.build.md
Last active January 21, 2021 18:18
Array.build(length, mapFn = undefined)
@ericelliott
ericelliott / es7-class.md
Last active March 25, 2021 10:27
Let's fix `class` in ES7

Two Simple Changes to Simplify class

I'm not suggesting drastic action. I don't want to break backwards compatibility. I simply want to make the class feature more usable to a broader cross section of the community. I believe there is some low-hanging fruit that can be harvested to that end.

Imagine AutoMaker contained class Car, but the author wants to take advantage of prototypes to enable factory polymorphism in order to dynamically swap out implementation.

Stampit does something similar to this in order to supply information needed to inherit from composable factory functions, known as stamps.

This isn't the only way to achieve this, but it is a convenient way which is compatible with .call(), .apply(), and .bind().

@cfj
cfj / console.clog.js
Last active April 2, 2021 18:17
console.clog
window.console.clog = function(log){
var message = typeof log === 'object' ? '%cLooks like you\'re trying to log an ' : '%cLooks like you\'re trying to log a ',
style = 'background:url(http://i.imgur.com/SErVs5H.png);padding:5px 15px 142px 19px;line-height:280px;';
console.log.call(console, message + typeof log + '.', style);
};
@shazron
shazron / delete_all_greenkeeper_branches.sh
Last active April 8, 2021 13:44
Delete all Greenkeeper branches
#!/bin/bash
# Description:
# Delete all `greenkeeper/*` branches of your remote.
# Instructions:
# Run the script with the `--help` flag.
ORIGIN=origin
DRY_RUN=0
THIS=`basename "$0"`
@OliverJAsh
OliverJAsh / foo.md
Last active May 31, 2021 07:25
JavaScript function declarations vs. expressions
@robotlolita
robotlolita / loops-are-evil.md
Last active March 2, 2022 17:19
Why `xs.each(f)` should not be considered a "loop".

First and foremost, let's take a look at the following pieces of code. The first one is something you should be rather familiar with, and the second one is also a somewhat familiar idiom these days (at least in languages with higher-order functions):

// Example 1:
30 + 12

// Example 2:
xs.map(f)