# litter-fun **Repository Path**: 1110qing/litter-fun ## Basic Information - **Project Name**: litter-fun - **Description**: No description available - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-07-31 - **Last Updated**: 2021-11-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # litter-fun # 在 XHR 文件夹里 ## 在浏览器中终端运行index.js时出现 require is not defined , exports is not defined ## 原因是require和exports是属于node.js中的一个模块系统,CommonJs规范中的,他们不存在浏览器客服端中,所以在浏览器中调用的话是无法调用的; ## 而在本地配置了node的就可以使用CommonJs 这一套模块系统,可以直接使用;当然在服务器上配置了node也是可以使用的; ## 这里涉及了node开始编译js模块的原理; ## 因为每一个js模块会被node全身包装,把作用函数包含在一个大的作用域中; ``` (function(exports,require.module,__filename,__dirname){ }) ``` # 可以在json文件夹中可以看到json文件的编译; ## 原理很简单: node 中引用 fs(文件流) 读取 json 内容,直接使用函数JSON.parse() 序列化json文件内容,再赋值给exports, 直接给外部使用;