Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* JavaScript dynamic `this` value.
*/
function produce() {
console.log(this.x);
}
const alpha = {produce, x: 1};
const beta = {produce, x: 2};
const gamma = {produce, x: 3};
console.log(
alpha.produce(), // 1
beta.produce(), // 2
gamma.produce(), // 3
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment