You are reading a single comment by @andrewg_oz and its replies. Click here to read the full conversation.
  • I've seen a lot of apps repeatedly use code like :

    require("module").function_call(foo);
    require("module").function_call(foo);
    require("module").function_call(foo);
    

    with the same module over and over. Is that a bad thing? I would have thought something like:

    var mod = require("module");
    // ...
    mod.function_call(foo);
    mod.function_call(foo);
    mod.function_call(foo);
    

    would be better if you're using the same module over and over? This is particularly noticeable for modules like "locale".

    The Modules page doesn't cover this, but uses the first convention. The entry for require uses the second as the example.

    I'd prefer the second (assigning to a variable), but I'd like confirmation that is best.

About

Avatar for andrewg_oz @andrewg_oz started