Last active
September 16, 2020 21:21
-
-
Save zgangx/1c31b8a67d3575fe7c1d23a2cc6262a3 to your computer and use it in GitHub Desktop.
Function invocation with apply
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
//this context change by using apply | |
var proxy = function(func, thisObject){ | |
return(function(){ | |
return func.apply(thisObject, arguments); | |
}); | |
}; | |
var clicky = { | |
name: 'my name is proxy', | |
wasClicked: function(){ | |
console.log(this.name) | |
}, | |
addListeners: function(){ | |
var self = this; | |
$('#my_p').click(proxy(this.wasClicked, this)) | |
} | |
}; | |
clicky.addListeners(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment