Книга: Functional Programming in JavaScript
Назад: Function expressions
Дальше: Unpredictable behavior

The function constructor

JavaScript actually has a third way to create functions: with the constructor. Just like function expressions, functions defined with the constructor are not hoisted.

var func = new Function('n','m','return n+m'); func(2,3); // returns 5

But the constructor is not only confusing, it is also highly dangerous. No syntax correction can happen, no optimization is possible. It's far easier, safer, and less confusing to write the same function as follows:

var func = function(n,m){return n+m}; func(2,3); // returns 5
Назад: Function expressions
Дальше: Unpredictable behavior

bsn
thank
Vesa Karvonen
I hope you don't mind, but I’d like to point you and your readers to my high-performance optics library for JavaScript that is in production use in multiple projects, has comprehensive support for partial optics and interactive documentation: https://calmm-js.github.io/partial.lenses/ (this takes a moment to load — be patient!)