(Day/Til 02.24)commonJSモジュール


I studied this today
  • npm, package.json
  • 矢印関数
  • CommonJS
  • package.json
    npmモジュールに関する情報を含むファイルは、このモジュールを利用する
    つまり、プロジェクト全体に関する情報が含まれています.
    npm : node.jsエコシステムのパッケージマネージャ
    {
      "name": "modern-javascript-koans",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      // 프로젝트에 관한 정보
      "scripts": {
        "test": "mocha modern-js-koans/*.js --sort",
        "report": "mocha modern-js-koans/*.js --sort --reporter @mochajs/json-file-reporter",
        "submit": "codestates-submission"
      },
      "keywords": [],
      "author": "codesatates",
      //스크립트는 CLI에서 사용가능한 명령들
      
      "dependencies": {
        "@codestates-cc/submission-npm": "^1.1.1"
      },
      "devDependencies": {
        "@mochajs/json-file-reporter": "^1.2.1",
        "chai": "^4.2.0",
        "mocha": "^8.2.0",
        "sinon": "^9.0.3"
      }
      // 개발과 관련된 dependency들
    }
    有効なモジュール=>$npm installをダウンロード
    モジュールを使用したテスト=>$npm run test
    モジュールコミット=>$npm run submitの使用
    矢印関数
    함수표현식
    const add = function (x, y) {
      return x + y
    }
    화살표 함수로
    const add = (x, y) =>  {
      return x + y;
    }  
    矢印関数規則
    関数本文(body)に1行のリターン記号しかない場合は、returnを省略して{}(カッコ)を使用しないでください.
    一般的な矢印関数のCloser関数の例
    함수 표현식
    const adder = function(x) {
      return function(y) {
        return x + y
      }
    }
    
    화살표 함수로
    const adder = x => {
      return y => {
       return x + y;
      }
    } 
    CommonJS
    誰もが独立した空間を持つべきだ.
    commonJSは関数だと思います.
    module.JSファイルをexportsでモジュール化します.
    エクスポートはモジュールです.これは輸出を弱めた.
    <hello.js>
    let x = 10;
    module.exports.x = 20;
    requierを導出してオブジェクトをロードします.
    const get = require("./hello.js")
    // get에는 20이 담긴다.