Advertisement
Guest User

hoisting + lazy evaluation

a guest
May 27th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. const plus = x => y => x + y;
  4.  
  5. const multiplyThenPlusWidth = x => y => plusWidth(x * y);
  6. const multiplyByTwoThenPlusWidth = multiplyThenPlusWidth(2);
  7.  
  8. // plusWidth() not initialised yet
  9. console.log(multiplyByTwoThenPlusWidth(5)); // works??
  10.  
  11.  
  12. const main = (() => {
  13.   // User input:
  14.   const w = 3;
  15.  
  16.   const plusWidth = plus(w);
  17.  
  18.   console.log(multiplyByTwoThenPlusWidth(5));
  19. })() // iife
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement