Skip to content

Instantly share code, notes, and snippets.

@getify
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getify/8911224 to your computer and use it in GitHub Desktop.
Save getify/8911224 to your computer and use it in GitHub Desktop.
another idea that'll never happen
// {?( .. ) opens up a conditionally compiled block.
// inside the ( .. ), you do a test, which is evaluated
// to see if the contents of the block should be compiled
// or not. If success, proceeds as a normal { .. } block
// of code. If test fails, entire contents of block
// are ignored and not compiled (no syntax errors)
//
// This would primarily be useful for using ES.next features
// that have breaking syntax. You construct a FT for the feature
// and if the test succeeds, use it, otherwise skip it.
//
// Basically, this is to avoid needing to do stuff like sticking
// ES6 code in a string passed to eval(..)
function foo() {
var fn;
{?( .. ) // use a feature-test for arrow-functions here
fn = () => this.baz * 3;
}
if (!fn) {
fn = function(){ return this.baz * 3; }.bind(this);
}
someOther(fn);
}
var obj = { baz: 10 };
foo.call(obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment