Posts tagged with 'invocation'

JavaScript for C# developers: calling functions and the ‘this’ variable

I can’t believe that I haven’t posted an article on how to call functions in JavaScript and what this gets set to for each of the various invocation patterns. It’s one of those things that catches people out periodically, so it’s well worth discussing at length. There are four different ways to call or invoke a JavaScript function: method invocation , function invocation , constructor invocation , and apply invocation . Each of these invocation patterns results in this being set to a different object...