13

I am studying the List.js Framework. This is a starting code. If I remove it(even remove the surrounding "()" of function e), Code is not working.

What is this? I think it is already defined in Javascript method.

(function e(t,n,r){
  function s(o,u){
   if(!n[o]){
    if(!t[o]){
    var a=typeof require=="function"&&require;
    if(!u&&a) return a(o,!0);
    if(i)return i(o,!0);
    var f=new Error("Cannot find module '"+o+"'");
    throw f.code="MODULE_NOT_FOUND",f
    }

    var l=n[o]={exports:{}};
    t[o][0].call(l.exports,function(e){
    var n=t[o][1][e];
    return s(n?n:e)
    },l,l.exports,e,t,n,r)
   }

 return n[o].exports
 }

 var i=typeof require=="function"&&require;
 for(var o=0;o<r.length;o++)
 s(r[o]);

 return s
}
)
Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
Hye Jin
  • 191
  • 1
  • 1
  • 7
  • 5
    It's minified code that allows you to work with modules. Browsers don't support modules out of the box (yet) and there are tools like Browserify that allow you to use [CommonJS](https://nodejs.org/docs/latest/api/modules.html) style modules in the browser. – Mike Cluck Sep 08 '16 at 19:15
  • OT, comparing minified to original source code can help here :) The name for "inverse" of minification is "source map" apparently. – Dima Tisnek Jan 09 '17 at 10:26
  • 1
    I disagree that this question is a duplicate. @MikeCluck 's answer is what I'm looking for, and it's not in the alleged original. – John Jan 29 '19 at 06:32
  • 1
    That piece of code defines "require" in the browser. Here's the non-minified version: https://github.com/browserify/browser-pack/blob/master/prelude.js – Gutimore Sep 21 '19 at 11:07

1 Answers1

6

It is a minified version of javascript (which does not make any actual difference, other than file size, and readability) so really, it is actually very much normal javascript code. However, written without the non compulsory syntax, unneeded whitespace, shorter variable names, all in efforts to reduce file transfer time.

Caspar Wylie
  • 2,818
  • 3
  • 18
  • 32
  • 3
    I think she is not asking what minified code is, but instead asks what that piece of code does. Also this question was incorrectly marked as duplicated by @mike-cluck . I gave the correct answer in the comments above. – Gutimore Sep 21 '19 at 11:17