Skip to content

Instantly share code, notes, and snippets.

@shaunwallace
Created November 19, 2014 13:54
Show Gist options
  • Save shaunwallace/04f221d06c7934cb7ba9 to your computer and use it in GitHub Desktop.
Save shaunwallace/04f221d06c7934cb7ba9 to your computer and use it in GitHub Desktop.
Function.prototype.bind()
function Shape() {
this.width = 100;
this.height = 100;
}
Shape.prototype.area = function() {
return this.width * this.height;
}
var square = new Shape();
square.area(); // returns 10000
var rectangle = {
width: 100,
height: 50
};
var rectangleArea = Shape.prototype.area.bind( rectangle );
rectangleArea(); // returns 5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment