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) |
logNow
islog
with 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:
base
is the object.name
is the property name.strict
istrue
ifuse strict
is in effect.
- The result of a property access
user.hi
is 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
+value
is not supported on bigints, we should useNumber()
to convert a bigint to a number.
Eval: run a code string
syntax
eval
is the result of the last statement.eval
is executed in the current lexical environment, so it can see outer variables – That’s considered bad practice.- In strict mode,
eval
has 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
eval
the 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.