封装一个获取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的模块接口有多种不同写法.这里作者对此做了个简单 ...
随机推荐
- 项目实战之poi导出excel
所需jar包 官方下载地址:http://mirrors.hust.edu.cn/apache/poi/release/bin/poi-bin-3.17-20170915.zip 1.前端调用方法: ...
- 一个shell脚本清空所有vim的配置!!
这个是从dyl的脚本那里偷过来的哈哈--(其实我现在还不是很懂shell [ -d .vim ] && mv -v .vim .vim.$(stat -c%Y .vim) [ -f . ...
- scapy基础-网络数据包结构
网络层次模型,数据包的组成是学习scapy的基础,下文主要关注模型中各个层次的用途,ethernet II和ip包数据结构. 1.五层模型简介 名称 作用 包含协议 应用层 面向程序对程序的传输 ...
- js验证手机号,身份证,车牌号验证
js验证手机号 <input type="text" class="identificationno"> // 身份证号码为15位或者18位,15 ...
- IDEA 的使用(快捷键、括号对齐的方式)
Java IDE 工具不是只有一个 Eclipse,还有同样十分优秀的 IDEA. 0. 常用快捷键 查看与设置:[File]⇒ [Settings]⇒ [Keymap] back/forward:c ...
- bzoj 1924 所驼门王的宝藏
题目大意: 有一个r*c的矩阵,上面有n个点有宝藏 每个有宝藏的点上都有传送门 传送门有三种:第一种可以传到该行任意一个有宝藏的点,第二种可以传到该列任意一个有宝藏的点,第三种可以传到周围的八连块上有 ...
- vue 目录结构介绍
1 初始目录如下: 2 目录结构介绍 bulid:最终帆布的代码存放位置 config:配置目录,包括端口号等 node_modules:npm加载的项目依赖模块 src:z这里是我们要开发的目录,基 ...
- uva1563
https://vjudge.net/problem/UVA-1563 高斯消元解同余方程组 就是把原来的除法换成逆元,其他的都一样 #include<bits/stdc++.h> usi ...
- Python 私有化类的属性
class MandgerSec: def __init__(self,name,gender,level): self.type=("fire",None) self.name= ...
- Spark 分布式环境---slave节点无法启动(已解决)
soyo@soyo-VPCCB3S1C:~$ start-slaves.sh soyo-slave01: starting org.apache.spark.deploy.worker.Worker, ...