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
const a = { value : 0 }; | |
a.valueOf = function() { | |
return this.value += 1; | |
}; | |
console.log(a==1 && a==2 && a==3); //true |
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
var value = 0; //window.value | |
Object.defineProperty(window, 'a', { | |
get: function() { | |
return this.value += 1; | |
} | |
}); | |
console.log(a===1 && a===2 && a===3) //true |
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 add(x){ | |
return function (y){ | |
return x+y; | |
} | |
} | |
//ES6 version using arrow functions | |
const add = x=> y=>x+y; |
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 add(x){ | |
let sum = x; | |
function resultFn(y){ | |
sum +=y; | |
return resultFn; | |
} | |
resultFn.valueOf = function(){ return sum }; | |
return resultFn; | |
} |
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 add(x){ | |
let sum = x; | |
return function resultFn(y){ | |
sum +=y; | |
resultFn.result = sum; | |
return resultFn; | |
} | |
} |
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 add(x){ | |
let sum = x; | |
return function resultFn(y){ | |
if(arguments.length){ //not relying on falsy value | |
sum += y; | |
return resultFn; | |
} | |
return sum; | |
} | |
} |
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 add(){ | |
let args = [].slice.apply(arguments); | |
function resultFn(){ | |
args = args.concat([].slice.apply(arguments)); | |
if(args.length>=3){ | |
return args.slice(0,3).reduce(function(acc,next){ return acc+next},0) | |
} | |
return resultFn |
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 fixCurry(fn, totalArgs){ | |
totalArgs = totalArgs ||fn.length | |
return function recursor(){ | |
return arguments.length<fn.length?recursor.bind(this, ...arguments): fn.call(this, ...arguments); | |
} | |
} | |
var add = fixCurry((a,b,c)=>a+b+c); | |
console.log('Add') |
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
#!/usr/bin/env bash | |
set -e | |
usage() { | |
echo "$0 <tag> <repo>" >&2; | |
} | |
if [ "$1" = "-h" -o "$1" = "--help" ]; then | |
usage |
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
#!/usr/bin/env bash | |
set -e | |
usage() { | |
echo "$0 <repo> <tag> [<release name>]" >&2; | |
} | |
if [ "$1" = "-h" -o "$1" = "--help" ]; then | |
usage |
OlderNewer