Skip to content

Instantly share code, notes, and snippets.

@andredublin
Created May 17, 2016 00:33
Show Gist options
  • Save andredublin/2cecc8f03795819f7507658bd612d0d6 to your computer and use it in GitHub Desktop.
Save andredublin/2cecc8f03795819f7507658bd612d0d6 to your computer and use it in GitHub Desktop.
self mapping object
var Person = function (name) {
this.name = name;
}
// ('a -> 'b -> Person<'b>)
Person.prototype.map = function (f) {
return new Person(f(this));
}
var me = new Person("Andre");
me.map(function(x) { return x.name + "!" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment