0

I have a codebase of javascript that I am working on, and have encountered a piece of structure that I am not familiar with. I would just like the name of it so I know what to look up and read about. Any additional information is appreciated.

This is in a Node.js/express environment.

What I'm specifically asking about is the fizz thing in file2.js, referenced in the line marked with a /*!!*/ in file1.js. It looks like some sort of wrapper around a series of functions. What is its proper name?

//file1.js

const file2 = require('filepath/file2')

foo.get('/bar', (req, res) => {
    file2.fizz.buzz(req.field.item, res)   /*!!*/
    localfunction(param1, param2)
})
//file2.js
module.exports = {
  fizz: {
      buzz: (str, res) => {
          console.log("buzz")
      },
      bang: (param1, param2) => {
          console.log("bang!")
      }
  }
}

Thanks!

7
  • 1
    Im not sure what is your question. if you are asking about the /*! */ sign here is a good answer for it stackoverflow.com/a/11248430/9453736 Commented May 28, 2019 at 14:44
  • 1
    An object? Or the word fizz itself? An object property (fizz being the property name, the object being the property value)? You might want to take a quick step back and spin through a JS tutorial real quick. Commented May 28, 2019 at 14:44
  • 1
    module.exports = {} -> module.exports is an object; fizz: {} -> the property fizz on module.exports is also an object;` buzz: (str, res) => {...}` -> the property buzz on module.exports.fizz is a function. x = require('file2.js'); x.fizz.buzz() is how you access that function. Commented May 28, 2019 at 14:46
  • Is there a name for wrapping multiple functions together like this in the fizz object? Commented May 28, 2019 at 14:46
  • 1
    The name for 'wrapping' multiple anything together in that format is simply called an object. You might also call it a 'map' Commented May 28, 2019 at 14:47

1 Answer 1

3

fizz is a property name (on the object referenced by the file2 variable).


Further Reading:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.