Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.

Exposing Internal Utils (Javascript)

  • 23-02-2017 03:44PM
    #1
    Registered Users, Registered Users 2 Posts: 1,298 ✭✭✭


    What do people think is a good way to do this, say i'm writing a project and want a single utils file that can contain some auth methods, helper methods etc etc, do you think using a node set up it would be better to do require('../../../../utils'); or perhaps expose it on the window object?


Comments

  • Registered Users, Registered Users 2 Posts: 403 ✭✭counterpointaud


    Any reason not to make it a module and declare it as a dependency?

    EDIT: BTW there is no window object in node, or is this supposed to run in the browser?


  • Registered Users, Registered Users 2 Posts: 1,298 ✭✭✭off.the.walls


    Any reason not to make it a module and declare it as a dependency?

    EDIT: BTW there is no window object in node, or is this supposed to run in the browser?

    Apologies, this is where my confusion lay, I know in terms of libraries such as jQuery they expose their functionality on the window. This is where I was hitting a wall with this!


  • Registered Users, Registered Users 2 Posts: 403 ✭✭counterpointaud


    Try and avoid putting things in global scope if you can help it. We have evolved a lot since the JQuery days, there are many options for modularization in Javascript.


Advertisement