Skip to main content
100%

Method/Function invocation pattern

✓ Published0🌍 Public
Aabernier
Last edited Jul 23, 2011
Created on Jul 23, 2011

This example illustrates the distinction between method invocation and function invocation patterns in JavaScript, focusing on how the `this` binding changes context. It shows that calling a function as a property of an object (e.g., `o.incr()`) binds `this` to that object, while invoking a standalone helper function (e.g., `helper()`) binds `this` to the global object, requiring a workaround like storing `this` in a variable (`that`). The code defines an object `o` with a `value` property and demonstrates both patterns through custom functions, using plain JavaScript without any external libraries.

AI-generated description

Similar vizzes