-
-
Save nishant8BITS/fa9f0fda702f3fc6095e8dc908e756d0 to your computer and use it in GitHub Desktop.
Early Binding & Late Binding in JavaScript
This file contains 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
// Early Binding vs Late Binding | |
// Early Binding | |
var sum = function(a, b) { | |
return a + b; | |
}; | |
var x = 5, y = 6; | |
var sum5n6 = sum.bind(null, x, y); | |
x = 10; | |
y = 5; | |
console.log("with Early Binding -->", sum5n6()); | |
// Late Binding | |
var sum2 = function(p) { | |
return p.x + p.y; | |
}; | |
var x = 5, y = 6; | |
var n = {x: x, y: y}; | |
var sumLate = sum2.bind(null, n); | |
n.x = 10; | |
n.y = 5; | |
console.log("Late Binding -->", sumLate()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment