Created
November 19, 2014 13:54
-
-
Save shaunwallace/04f221d06c7934cb7ba9 to your computer and use it in GitHub Desktop.
Function.prototype.bind()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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