0

I keep seeing this pattern of value replacement, and I'm trying to figure out how I can explain the substitution to my coworkers.


Question

What are the proper, definitive words for:

  1. this substitution
  2. the substituted function

In many applications, you need to re-query the value rather than use an existing, defined variable.

Advanced use-cases:

  1. trampolining
  2. using functions as React children, rather than JSX / HTML

Example Animation

const initialValue = (
  +(0.5 * window.innerHeight)
);

const remainingValue = (
  -(initialValue)
  +(0.25 * window.innerHeight)
);

function getTopValue (percentageComplete) {
  return (
    +(initialValue)
    +(percentageComplete * remainingValue)
  );
}

If you were to call getTopValue over a few seconds with values between 0 and 1, you eventually end up at initial + remaining

However, if you are to resize the screen, your end destination is different, and you must turn remainingValue into a function, rather than a value

const initialValue = (
  +(0.5 * window.innerHeight)
);

const remainingValue = () => (
  -(initialValue)
  +(0.25 * window.innerHeight)
);

function getTopValue (percentageComplete) {
  return (
    +(initialValue)
    +(percentageComplete * remainingValue())
  );
}
neaumusic
  • 10,027
  • 9
  • 55
  • 83

1 Answers1

0
  1. lazy evaluation -- strategy which delays the evaluation of an expression until its value is needed
  2. thunk -- a parameterless closure created to prevent the evaluation of an expression until forced at a later time
neaumusic
  • 10,027
  • 9
  • 55
  • 83