封装一个获取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的模块接口有多种不同写法.这里作者对此做了个简单 ...
随机推荐
- iOS开发——基础篇——get和post请求的区别
HTTP 定义了与服务器交互的不同方法,最常用的有4种,Get.Post.Put.Delete,如果我换一下顺序就好记了,Put(增),Delete(删),Post(改),Get(查),即增删改查,下 ...
- ROUND function and arithmetic overflow
遇到如下错误 Arithmetic overflow error converting expression to data type numeric. ), ); https://stackover ...
- flash builder 4.6 下载完成后安装不成功
从网上下载了一下flash builder 4.6 下载完成后安装不成功,说是有一个安装被挂起,不成安装成功结果从注册表中删除了pendingobject,还是不行,没有办法,从网上搜了一下,发现了大 ...
- ViewControl的size设为freeform
freeform的用处是让你写一些不标准的view,比如说自定义一个cell,或者自己写一个小的VIEW,freeform的XIB是可以自己拖拽更改大小的
- http报文和协议首部
http报文和协议首部 http报文 3>报文格式 request 报文 <method> <request-URL> <version> <heade ...
- c++ class does not name a type (转载)
转载:http://blog.csdn.net/typename/article/details/7173550 declare class does not name a type 出现这个编译错误 ...
- PCB Genesis加邮票孔(弧与弧)实现算法
一.Genesis加邮票孔(弧与弧)实现算法 1.鼠标点击位置P点(可以确认搜索区域位置,确认点击位置周边元素分区,此所讲算法未应用到P点坐标) 2.求出:P1C与P2C (线与弧最近点距离的2个点) ...
- E20180109-E
auxilary adj. 辅助的; 备用的,补充的; 附加的; 副的; n. 助动词; 辅助者,辅助人员; 附属机构,附属团体; 辅助设备;
- hdu 2209 翻纸牌游戏【贪心】
本来是冲着搜索去的--其实可以贪心 因为能改变第一位的只有第一位和第二位,然后改完之后后面的同理,也就是说只要贪心的推一遍就可以 但是注意要在翻第一个和不翻第一个之间取个min #include< ...
- bzoj2093: [Poi2010]Frog(单调队列,倍增)
2093: [Poi2010]Frog Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 568 Solved: 186[Submit][Status] ...