by austin-cheney · 2y ago · 0 comments
A series of function calls that each do something and each returns a value.
> Okay, here's an easier question. What will happen here, and why?
A function call that does something and returns a value, because in this language complex types are passed by reference.
Doesn't make it functional
> A function call that does something and returns a value,
Ah, so you don't know.
Here's what will actually happen:
TypeError: Can only call Document.getElementById on instances of Document
Because it's a method on an object. And you have to bind that method to a specific object instance before you can call it.If it was functional this would never be the case. But since this is 90s-era OOP, you have to do this:
const function_reference = document.getElementById.bind(document);
function_reference("#id");This is not what functional programming is. Functional programming is a completely different paradigm for writing code, and it _is_ declarative by definition. The Wikipedia definition is pretty decent:
Functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.
The "Comparison to imperative programming" section[1] offers a decent example of the paradigm, but DOM manipulation in JavaScript is pretty much as imperative as it gets. Having functions is necessary, but not sufficient, for functional programming.[1]: https://en.wikipedia.org/wiki/Functional_programming#Compari...
Functional programming uses stateless, immutable transformations to contorl data flow. The second you instantiate an object with some internal properties that change in memory, you are no longer programming functionally