封装一个获取module.exports内容的方法
let fs = require('fs')
let req = (moduleName) => {
//content代表的是文件内容
let content = fs.readFileSync(moduleName, 'utf8')
console.log(content + '\n return module.exports')
//最后一个参数是函数的内容体
let fn = new Function('exports','module','require','__dirname','__filename',content + '\n return module.exports')
let module = {
exports:{}
}
return fn(module.exports,module,req,__dirname,__dirname)
}
let msg = req('./a.js')
console.log(msg.msg)
封装一个获取module.exports内容的方法的更多相关文章
- JavaScript封装一个函数效果类似内置方法concat()
JavaScript封装一个函数效果类似内置方法concat() 首先回忆concat()的作用: concat() 方法用于连接两个或多个数组.该方法不会改变现有的数组,而仅仅会返回被连接数组的一个 ...
- nodeJs--模块module.exports与实例化方法;
在nodejs中,提供了exports 和 require 两个对象,其中 exports 是模块公开的接口,require 用于从外部获取一个模块的接口,即所获取模块的 exports 对象.而在e ...
- nodeJs--模块module.exports与实例化方法
在nodejs中,提供了exports 和 require 两个对象,其中 exports 是模块公开的接口,require 用于从外部获取一个模块的接口,即所获取模块的 exports 对象.而在e ...
- Node.js中exports,module.exports以及require方法
在Node.js中,使用module.exports.f = ...与使用exports.f = ...是一样的,此时exports就是module.exports的一种简写方式.但是,需要注意的是, ...
- js实现默认或者触发一个事件选中元素内容的方法
方法一:非文本框.文本域的选中内容方法 <!Doctype html> <html> <head> <script type="text/javas ...
- html提交表单,php在后台获取表单内容的方法_例1
html代码: <html> <head> <meta http-equiv="Content-Type" content="t ...
- 封装一个axios请求后台的通用方法
import axios from 'axios'; import constant from '@/js/const'; import alert from '@/js/alertView'; le ...
- Node.js中exports与module.exports的区别
原文:http://www.hacksparrow.com/node-js-exports-vs-module-exports.html 你肯定对Node.js模块中用来创建函数的exports对象很 ...
- Node.js中的模块接口module.exports浅析
在写node.js代码时,我们经常需要自己写模块(module).同时还需要在模块最后写好模块接口,声明这个模块对外暴露什么内容.实际上,node.js的模块接口有多种不同写法.这里作者对此做了个简单 ...
随机推荐
- ldd LD_TRACE_LOADED_OBJECTS
1 该环境变量设置为1的话,只会打印所执行的程序的依赖,即所依赖的动态链接库
- PNG vs. GIF vs. JPEG vs. SVG - When best to use?
image - PNG vs. GIF vs. JPEG vs. SVG - When best to use? - Stack Overflow https://stackoverflow.com/ ...
- 局部优化与整体效果 新增时间>节省时间 权衡利弊
原代码 from selenium import webdriverimport requests,timeurl_l=[]with open('DISTINCT_url.txt', 'r', enc ...
- sql语句如何查询当天,一周,一月的数据的语句
sql查询当天,一周,一个月数据的语句 --查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: ...
- 洛谷 P1045 麦森数
题目描述 形如2^{P}-1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果P是个素数,2^{P}-1不一定也是素数.到1998年底,人们已找到了37个麦森数.最大的一个是P=30213 ...
- Java泛型Object和?区别
在写spark streamming读取kafka latest offset的时候,有一下语句: Map<TopicAndPartition, Object> latestOffsets ...
- 在dataGridView空间中添加数据
//查询信息sql语句 string sql = "select studentName,addres from student"; SqlDataAdapter adapter ...
- Echarts和Quartz简介
一.Echarts ECharts 是由百度前端团队开发的一款开源的基于 js 图形报表组件,一个使用 JavaScript 实现的开源可视化库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大 ...
- [ CodeForces 438 D ] The Child and Sequence
\(\\\) \(Description\) 维护长为 \(N\) 的数列,\(M\)次操作,支持单点修改,区间取模,查询区间和. \(N,M\le 10^5\) \(\\\) \(Solution\ ...
- 第八届蓝桥杯省赛C/C++ A组第4题 方格分割
参考了http://blog.csdn.net/y1196645376/article/details/69718192,这个大哥的思路很巧妙. 思路: dfs. 实现: #include <i ...