MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Syntax Style for node_helper.js

    Scheduled Pinned Locked Moved Development
    6 Posts 3 Posters 334 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • kayakbabeK Offline
      kayakbabe
      last edited by kayakbabe

      I’m looking at a lot of modules while trying to roll my own and see a lot of differences in syntax style, I wonder if one way of creating a function is better or more efficient than the other.

      init: function () and init()

      I see both ways done in node_helper.js in different modules.

      module.exports = NodeHelper.create({
          init: function () {
            console.log ("init module helper ");  
          }
      })
      

      and

      module.exports = NodeHelper.create({
          init () {
            console.log ("init module helper ");  
            }
      });
      
      S KristjanESPERANTOK 2 Replies Last reply Reply Quote 0
      • S Away
        sdetweil @kayakbabe
        last edited by sdetweil

        @kayakbabe doesnt matter, only processed once at page load

        older versions of nodejs only supported type 1

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 1
        • KristjanESPERANTOK Offline
          KristjanESPERANTO Module Developer @kayakbabe
          last edited by

          @kayakbabe said in Syntax Style for node_helper.js:

          I see both ways done in node_helper.js in different modules.

          The short variant is known as “Shorthand Method Names” and has been available since 2015 (with the release of ECMAScript 6).

          https://ui.dev/shorthand-properties#shorthand-method-names

          kayakbabeK 1 Reply Last reply Reply Quote 0
          • kayakbabeK Offline
            kayakbabe @KristjanESPERANTO
            last edited by

            @KristjanESPERANTO abd @sdetweil

            for MagicMirror purposes, is there a preferred style to be used for modules?

            S KristjanESPERANTOK 2 Replies Last reply Reply Quote 0
            • S Away
              sdetweil @kayakbabe
              last edited by

              @kayakbabe no… up to you

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 1
              • KristjanESPERANTOK Offline
                KristjanESPERANTO Module Developer @kayakbabe
                last edited by KristjanESPERANTO

                for MagicMirror purposes, is there a preferred style to be used for modules?

                @kayakbabe I agree with Sam, but here’s a more detailed answer anyway: This depends on where you are. In some modules there are no rules for this - there and in your own modules it is, as Sam says, up to you.

                However, to avoid poor code style, such as spaghetti code and inconsistently formatted code, which not only make maintenance and further development more difficult, but also affect team collaboration, many projects use static code analysis tools such as prettier and ESLint for checking code quality.

                In the MagicMirror core (and with this in the default modules), we use the ESLint object-shorthand rule (see https://archive.eslint.org/docs/rules/object-shorthand) to ensure that only the shorthand version is used.

                1 Reply Last reply Reply Quote 1
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Sam, technical setup by Karsten.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy
                  OSZAR »