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:
- this substitution
- the substituted function
In many applications, you need to re-query the value rather than use an existing, defined variable.
Advanced use-cases:
- trampolining
- 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())
);
}