Skip to content

Instantly share code, notes, and snippets.

@zgangx
Last active September 16, 2020 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zgangx/1c31b8a67d3575fe7c1d23a2cc6262a3 to your computer and use it in GitHub Desktop.
Save zgangx/1c31b8a67d3575fe7c1d23a2cc6262a3 to your computer and use it in GitHub Desktop.
Function invocation with apply
//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