Skip to content

Instantly share code, notes, and snippets.

@CrypticSwarm
CrypticSwarm / handlerMaker.js
Created September 28, 2011 05:16
Harmony Proxies experiment.
//From http://wiki.ecmascript.org/doku.php?id=harmony:proxies
function handlerMaker(obj) {
return {
getOwnPropertyDescriptor: function(name) {
var desc = Object.getOwnPropertyDescriptor(obj, name);
// a trapping proxy's properties must always be configurable
if (desc !== undefined) { desc.configurable = true; }
return desc;
},
getPropertyDescriptor: function(name) {
// Flow is a construct that can chain together functions.
// Flow denotes regular function composition.
var chain1 =
Flow <- f1
<- f2
<- f3
chain1(123) // same as f3(f2(f1(123)))
// Can also chain together multiple things that go to one.
@CrypticSwarm
CrypticSwarm / broken.js
Created August 8, 2012 02:45
Showcases a subtle problem that can occur due to getters.
var optimist = require('optimist')
optimist.demand('color')
optimist.demand('size')
optimist.argv