Classes are in no way functions in the FP sense because classes mutate state.
Classes are in no way functions because calling methods requires the instantiation of unrelated state. Example:
class A
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
self.banana = create_banana(create_gorilla(create_jungle()))
def process_a(self):
return process(self.a)
process_a cannot be used unless a, b, c and the banana plus the gorilla holding the banana and the entire jungle the gorilla lives in is instantiated.Let's talk about terminology. There are three that often get mixed up.
Procedure = a set of instructions that could encompass mutating and changing state.
Function = a box that when given input produces an output. The box cannot modify the universe. It can only produce something new when given an input.
Object = A grouping of a set of procedures and state that can mutate.
The javascript programmer OP is mixing up function and procedure. He defines a procedure and says that it can be a class. A procedure can be a class as it's just a set of instructions which can encompass defining scope, state and more procedures restricted to scope and state (aka an object).This thing right here, written by the OP:
function setFirstName(firstName) {
fName = firstName
}
Is not a function... it is a method or a procedure that mutates state.A function can do none of the above.
That's it.