I can’t seem to get back on track with this one. I simply put a function in a variable and want to call it later, providing it with a parameter:
var logic = function(itemId) {
console.log(itemId);
};
jQuery("#flipright").click(function() { logic.apply(1); } );
This prints “undefinded”.
What am I missing?
Simply call
logic(1).If you want to pass a context, you can use
callorapply:You should use
applyorcallif you want to pass a context to another function – meaning that thethiskeyword in the called function will refer to whatever context you are passing to it.Here’s a scenario :