bookmark

JS scope: static, dynamic, and runtime-augmented – codeburst


Description

Definition 4: This value: in JavaScript this value is dynamically scoped, unless used in an arrow function.

That’s correct: as we know, the value of this is determined and provided exactly by the caller.

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 );

Preview

Tags

Users

  • @jil

Comments and Reviews