jjzjj

javascript - ES6 命名空间导入 : behavior of "this"

从命名空间导入调用的导入函数中,this的值是多少?(根据ECMA规范)//module.jsexportfunctionfun(){returnthis;}//main.jsimport*asmodulefrom"./module.js";letx=module.fun();//What'sthevalueofxhere?我的猜测是:它是module对象,但在规范中还没有找到明确的答案。正常行为是否适用于此,或者在ES6模块中是否有一些特殊的namespace导入? 最佳答案 没有,这里没有特殊行为。Modulenamespace

javascript - 为什么我们需要将 module.exports 作为参数传递,因为我们已经将 module 作为参数传递了?

我一直在阅读一些关于Node.js的在线教程。我的理解是,在使用require(./file-path)函数时,Node获取该文件的内容并包装在一个立即调用的函数中(function(exports,require,module,__filename,__dirname){//content}())我了解exports和module.exports之间的区别。这就是我在互联网上搜索上述问题时所能看到的全部内容。但我的问题是,为什么我们需要将module.exports和module传递给包装IIFE?我们可以单独传递模块,然后从中获取module.exports。这样做有什么好处吗?通

javascript - react : Flow: Import a local js file - cannot resolve issue module

我正在使用Flow:Statictypecheckinglibrary对于React前端应用程序,它会为从src目录的内部导入抛出“无法解析”:Exampleinfileatpath:src/abc/def/ghi/hello.jsx,Iamusingthefollowingimport:importwordsfrom'../words';-->Throwserror"Cannotresolvemodule../wordswords.jsisinsrc/abc/defdir已编辑:安装flow-typed后,我的.flowconfig看起来像这样:[ignore].*/node_mod

javascript - 错误 : "Could not find a declaration file for module ' react-search-input'"

我正在尝试安装react-input-search。我有错误:Couldnotfindadeclarationfileformodule'react-search-input'.'.../app/node_modules/react-search-input/lib/index.js'implicitlyhasan'any'type.Trynpminstall@types/react-search-inputifitexistsoraddanewdeclaration(.d.ts)filecontainingdeclaremodule'react-search-input';ts(70

javascript - 如何在 node.js 中使用原型(prototype)

我在nodejs上编写了我的第一个模块。我需要从谷歌缓存中解析我的网站。帖子是表格帖子的map。当我尝试使用此模块时出现此错误:“类型错误:无法设置未定义的属性‘原型(prototype)’”如何修复这个错误?这是我的代码:module.exports=functionPost(documentDOM,options){this.opts=$.extend({id:0,author_id:0},options);this.doc=documentDOM;this.post={id:0,name:'',alt_name:'',notice:'',content:'',author:'',

javascript - 如何在requirejs、javascript中的不同模块之间共享数据

我想通过创建一个模块在不同模块之间共享一些数据,例如调用dataService,将一个变量放入其中,然后将该模块作为依赖项插入其他模块中。这是代码(不起作用):define('dataService',function(){varquotes=[];return{quotesArray:quotes,};});require(['dataService'],function(dataService){dataService.quotesArray{1,2,3};//settingthequotesvariable});define('otherModule',['dataService

javascript node module.exports/require() 前端代码

我一直在研究使用像SVGO这样的库能够在前端清理用户提交的SVG代码。SVGO是一个基于node.js的库,通常在后端运行,所以我一直在努力思考如何将SVG代码从前端发送到后端,然后将清理过的代码反刍到前端。正是在我试图弄清楚这一点的时候,我检查了他们的webappexample,经检查,在链接脚本中运行代码,我通常会在前端的后端看到这些代码。特别是,它们的许多函数都具有签名(fullscript):1:[function(require,module,exports){"usestrict";varloadScripts=require("./load-scripts"),...mo

javascript - TS1148 ~ 如何使用 --module : "import" and typescript 2. x "none"

我目前正在使用一些旧版JavaScript开发一个项目。该应用程序不包含模块加载器,它只是将所有内容作为全局变量放入window对象中。遗憾的是,接触遗留代码并包含模块加载器对我来说不是一个可行的选择。我想在我自己的代码中使用typescript。我设置了typescript编译器选项module:"none"在我的tsconfig.json中,我只使用命名空间来组织我自己的代码。到目前为止效果很好。..到现在为止:import*asRxfrom'rxjs';..Rx.Observable.from(['foo',bar']);...//ResultsinTypeScript-Erro

javascript - import {module} 和 import module 的区别

这个问题在这里已经有了答案:`exportconst`vs.`exportdefault`inES6(6个答案)usingbracketswithjavascriptimportsyntax(2个答案)WhenshouldIusecurlybracesforES6import?(11个答案)关闭5年前。我看到了以下两种从ES6中的另一个模块导入代码的变体:import{module}from"./Module"和importmodulefrom"./Module"其中module是文件中定义的ES6类Module.js这两个导入语句有什么区别?

javascript - esm 不解析模块别名

所以我正在使用包esm和module-alias,但似乎esm没有注册模块别名的路径。这是我加载服务器文件的方式:nodemon-resm./src/index.js8081这是我的index.js文件的顶部:import"module-alias/register"import"@/setup"import"@/setup"不起作用,而require("@/setup")起作用。 最佳答案 问题是esm在解析文件时试图在加载任何其他模块之前处理所有import语句。在处理import语句时,它使用Node的内置require而不是