• Regarding the ()...:

    Think about of these as the execution or invocation method of the function object. In JS, all things are object... sounds like my screen name... does it? ...and sorry when it feels 'me being obsessed with objects'... I'am, kind-a, but it gets and keeps my daily job robustly going.

    Therefore, functions are objects as well. To 'get them going', you just throw () at them without parameters, or with a parameter list (parm1,parm2,...), and there you have it... thats why you find https://developer.mozilla.org/en-US/docs­/Web/JavaScript/Reference/Global_Objects­/Function as prototype (class) definition, with all its methods, such as .bind()... JavaScript syntax makes then life easy for you and provides you with the short cut:

    function myFun() { console.log("haha"); }
    

    which is nothing else then:

    var myFun = function() { console.log("haha"); }
    

    or even more cumbersome:

    var myFun = new Function('console.log("haha");');
    

    Entering

    myFun
    

    just returns the function as object

    myFun()
    

    fires it to say: haha

    Interesting - but expected from how JS works - is when requiring module that returns a constructor (class), that the require has to be 'precedenced' / precedence enforced with parentheses, and only after that requires completes, the new with or without parameters in parentheses can be thrown/applied at it:

    var stopWatchAutoStarted = new (require("StopWatch"))("autostart");
    

    Otherwise, the new goes against the require, and require is not a constructor with the module name as a parameter / will fail as a constructor... This fact shows the weird or mixed design of the new key word as part of the language syntax. In a clean oo language this would read: require("ModuleReturninClass").new(param­1, param1,...), with .new(...) being a class method. require(...) would then also not be a free floating function... it has at least to be a class method of the Module class... Because in a clean oo language practically only labeled instances are globally known, and classes are instances of the class Class and are labeled by their name, they are globally visible.

    There is more to - this - OO and Lambda (Calculus) constructs... Lambda Calculus, - something 'discovered'/formulated in the 30'. ...and about that may be at another occasion... -

About

Avatar for allObjects @allObjects started