• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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 713 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.
  • K Offline
    kayakbabe
    last edited by kayakbabe Mar 2, 2025, 1:38 PM Mar 2, 2025, 1:37 PM

    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 K 2 Replies Last reply Mar 2, 2025, 1:52 PM Reply Quote 0
    • S Offline
      sdetweil @kayakbabe
      last edited by sdetweil Mar 2, 2025, 1:53 PM Mar 2, 2025, 1:52 PM

      @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
      • K Offline
        KristjanESPERANTO Module Developer @kayakbabe
        last edited by Mar 2, 2025, 11:43 PM

        @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

        K 1 Reply Last reply Mar 5, 2025, 4:24 AM Reply Quote 0
        • K Offline
          kayakbabe @KristjanESPERANTO
          last edited by Mar 5, 2025, 4:24 AM

          @KristjanESPERANTO abd @sdetweil

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

          S K 2 Replies Last reply Mar 5, 2025, 4:31 AM Reply Quote 0
          • S Offline
            sdetweil @kayakbabe
            last edited by Mar 5, 2025, 4:31 AM

            @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
            • K Offline
              KristjanESPERANTO Module Developer @kayakbabe
              last edited by KristjanESPERANTO Mar 5, 2025, 9:38 AM Mar 5, 2025, 9:28 AM

              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
              1 / 1
              • First post
                4/6
                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