C
C
CoyoteSS2019-05-12 19:08:00
JavaScript
CoyoteSS, 2019-05-12 19:08:00

Most JS frameworks have such a piece of code at the beginning, please explain what happens on each line?

What is inside, in principle, is clear, this is functionality, but at the beginning it is not clear to me why this check is needed at the beginning? It's in Vue, ReactJS etc.;

(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  typeof define === 'function' && define.amd ? define(factory) :
  (global.React = factory());
}(this, (function () { 'use strict';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-05-12
@CoyoteSS

Universal Module Definition
About modules, formats, loaders and assemblers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question