0

What does the underscore after "state.triggeredTests =" mean:

mutations: {

setTriggeredTest(state, data) {

  state.triggeredTests = _
    .chain(data)
    .forEach((item) => {
      item.dateFormatted = moment(item.date).format('DD MMMM YYYY');
      item.explanationTest = testMapping.get(item.test);
    })
    // .sortedUniqBy('explanationTest')
    .orderBy('date')
    .groupBy('date')
    .value();
},

2 Answers 2

3

Its a library of function/utilities/helpers which generally can be either lodash or underscore

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

2 Comments

so, it is something like a namespace in C++ ?
Sort of, _ is a valid variable declaration allowed in Javascript, so libraries like underscore or lodash just use that declaration using var _ = (function() {...})(); to point to their public functions which are available to you and which may or may not be chainable depending on library. Similar example is $ declaration which usually people identify as jQuery or Prototype library.
3

_ is the completely valid identifier in JS. _ global variable is being traditionally used by the underscore library and its clones as a namespace.

P.S.: $ is the valid identifier as well, and it's being used by jQuery or similar libraries.

1 Comment

Worth noting that OP's example is actually lodash as opposed to underscore, AFAICT.

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.