In languages like Java, C# and Visual Basic, you program everything in classes - they are the "citizens" of first class. The method Main
that starts your program is a member of a class. The objects you encode are all instances of classes someone wrote. Open your IDE and see... In C#code, the only things you write outside the scope of classes are decoration (for the classes themselves), declaration of new namespaces (namespaces) and declaration of which namespaces will be used.
In Javascript there are no classes - at least not in the same way as in other languages. The typification is completely different. There are some basic types (number
, date
, string
, boolean
and array
, if I remember correctly) and the guy object
. But they’re not classes. You have, so to speak, classless objects.
And here the cat jump: Javascript types are functions. If you want to create a new type, you declare a function. It becomes a constructor of itself, and all the members you assign directly to it are static. To give instance members to your type, you associate them with the prototype (prototype) of function.
Since every type you write on your own in Javascript will necessarily be a function, we say that in Javascript, the functions are the objects (or "citizens" as defined in) first-class.
To complete: one function can return another function.
– bfavaretto