I'm confused as to what the purpose or use cases are for functions being able to have method calls in JavaScript. I understand that functions are considered objects and thus can have their own properties and therefore functions, but it seems to me like it is still a little bit different than what I would call a standard object. For example, why would i ever do this...
var myFunction = function(){...};
myFunction.method = function(){...};
Instead of creating an object and having one or more function properties like the following...
var obj = {method: function(){}};
And if we were to console.log each we get the following...
console.log(myFunction);
console.log(obj);
------------------------------------------
{ [Function] secondFunction: [Function] }
{ method: [Function] }
I'm trying to learn the Express.js framework currently and it seems like it makes heavy use of this concept. What is the point? Is this what is meant by a top level function?