Currying
Translates a function from callable as f(a, b, c) into callable as f(a)(b)(c).
Example
1 | log(new Date(), "DEBUG", "some debug"); // log(a, b, c) |
logNowislogwith fixed first argument, in other words “partially applied function” or “partial” for short.Advanced curry implementation ??
Reference Type
The value of Reference Type is a three-value combination (base, name, strict), where:
baseis the object.nameis the property name.strictistrueifuse strictis in effect.
- The result of a property access
user.hiis not a function, but a value of Reference Type.
1 | strict mode |
- Reference type is a special “intermediary” internal type, with the purpose to pass information from dot
.to calling parentheses().
BigInt
BigInt is created by appending n to the end of an integer literal or by calling the function BigInt() that creates bigints from strings, numbers etc.
- All operations on bigints return bigints.
5n / 2n // 2 - We can’t mix bigints and regular numbers.
- The unary plus
+valueis not supported on bigints, we should useNumber()to convert a bigint to a number.
Eval: run a code string
syntax
evalis the result of the last statement.evalis executed in the current lexical environment, so it can see outer variables – That’s considered bad practice.- In strict mode,
evalhas its own lexical environment. So functions and variables, declared insideeval, are not visible outside
1 | let value = eval('let i = 0; ++i'); |
Using eval
- Now, we can replace it with a modern language construct or a JavaScript
Module. - To
evalthe code in the global scope, usewindow.eval(code). - Needs some data from the outer scope, use
new Function('a', 'alert(a)')and pass it as arguments.