Книга: Functional Programming in JavaScript
Назад: Gotchas
Дальше: Function declarations

Function declarations versus function expressions versus the function constructor

What is the difference between these three statements?

function foo(n){ return n; } var foo = function(n){ return n; }; var foo = new Function('n', 'return n');

At first glance, they're merely different ways to write the same function. But there's a little more going on here. And if we're to take full advantage of functions in JavaScript in order to manipulate them into a functional programming style, then we'd better be able to get this right. If there is a better way to do something in computer programming, then that one way should be the only way.

Назад: Gotchas
Дальше: Function declarations

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!)