Skip to content

Instantly share code, notes, and snippets.

@saschanaz
Last active August 29, 2015 14:05
Show Gist options
  • Save saschanaz/c97a29e9d24355436f38 to your computer and use it in GitHub Desktop.
Save saschanaz/c97a29e9d24355436f38 to your computer and use it in GitHub Desktop.
Design proposal: Syntax sugar for function calling

Syntax

"abc"<-Array.prototype.map((c) => c);

var uint8array: Uint8Array;
var array = uint8array<-Array.prototype.map((i) => i);

Compiles to:

Array.prototype.map.call("abc", function (c) { return c; });

var uint8array;
var array = Array.prototype.map.call(uint8array, function (i) { return i; });

In conjunction with extension functions

function map(callbackfn: (value: any, index: number, array: Uint8Array) => number) joins {} {
  return Array.prototype.map.call(this, callbackfn);
}

"abc"<-map((c) => c);

var uint8array: Uint8Array;
var array = uint8array<-map((i) => i);

Compiles to

function map(_this, callbackfn) {
  return Array.prototype.map.call(_this, callbackfn);
}

map("abc", function (c) { return c; });

var uint8array;
var array = map(uint8array, function (i) { return i; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment