This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Adds 'delve' to the Object prototype for accesing nested properties. | |
*/ | |
if (!Object.prototype.delve) { | |
Object.prototype.delve = function(compositeKey) { | |
return compositeKey | |
.split('.') | |
.reduce((obj, key) => obj[key], this); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Usage: | |
# | |
# python tabs2spaces.py . 2 .*\.js$ | |
# | |
import argparse | |
import os | |
import re | |
parser = argparse.ArgumentParser(description='Replace tabs with spaces.') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* func1() { | |
var y = yield 'b'; | |
console.log('y = ', y); | |
return 'c'; | |
} | |
function* func() { | |
var x = yield 'a' | |
console.log("x = ", x); | |
var z = yield* func1(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example how annotations can be easily added to JavaScript functions, however there is no need in this | |
* as unlike in statically typed languages in JavaScript it is already possible to add various fields to functions | |
*/ | |
(function() { | |
if (Function.prototype._annotations) { | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* func() { | |
var x = yield 'a' | |
console.log("x = ", x); //1 | |
var y = yield 'b' | |
console.log("y = ", y); //2 | |
return 'c'; | |
} | |
var it = func(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Showcases how arrays can be easily concatenated with values in ES6 | |
var x = [1, 2, 3]; | |
var y = [4, 5, 6]; | |
var z = 7; | |
var arr = [...x, ...y, z]; | |
console.log(arr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm install browserify -g | |
// npm install tsd -g | |
// npm install react tsify | |
// tsd install react | |
// browserify app.tsx -p [tsify --jsx=react] -o bundle.js | |
/// <reference path="typings/react/react.d.ts" /> | |
import React = require("react"); | |
interface HelloWorldComponentProps extends React.Props<any> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Demonstrates how constructor arguments can be expanded if supplied as an array. | |
*/ | |
function createWithArgs(constructor, args) { | |
var boundArgs = [null].concat(args); | |
var boundConstructor = Function.prototype.bind.apply(constructor, boundArgs); | |
//When 'boundConstructor' is invoked with new, | |
//'this' will point to object being constructed, not 'null' | |
return new boundConstructor(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* One way to make arguments of a function an array in JavaScript with less boilerplate. | |
*/ | |
Function.prototype.enhance = Function.prototype.enhance || function() { | |
var self = this; | |
return function() { | |
var oldValue = this._args; | |
try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Computes the color to be specified in CSS which will be visually equivalent to | |
* <b>desiredColor</b> when the transparency is <b>alpha</b>. | |
* Based on the method suggested in http://stackoverflow.com/questions/12228548/findinq-equivalent-color-with-opacity | |
* | |
* @options.backgroundColor - | |
* background color against which the computed background color will be overlayed | |
* @options.desiredColor - | |
* desired color appearance in case alpha is 1 | |
* @options.alpha - |