草庐IT

Merge函数

全部标签

javascript - 返回 Promise<void> 的异步函数是否在 block 末尾有隐式返回?

publicasyncdemo():Promise{//Dosomestuffhere//Doingmorestuff//...//Endofblockwithoutreturn;}是新的Promise在TypeScript/ES6的block末尾隐式返回?bool类型的例子:classTest{publicasynctest():Promise{returntrue;}publicmain():void{this.test().then((data:boolean)=>{console.log(data);});}}newTest().main();这会打印出true到控制台,因为r

javascript - 从模块中调用 Node.js 模块函数

我正在尝试编写一个Node模块以清理我的代码并将其分离到不同的文件中。考虑下面的代码:module.exports={Hello:function(request,reply){returnreply("Hello"+World());},World:function(){return"World";}}如果我导入上述模块并使用Hello函数作为特定路由的处理程序,我会收到HTTP500内部服务器错误。如果我将Hello函数更改为,我已将问题缩小到对World()的调用Hello:function(request,reply){returnreply("HelloWorld");}然后

javascript - Firestore + 云函数 : How to read from another document

我正在尝试编写一个从另一个文档读取的Google云函数。(其他文档=不是触发云功能的文档。)弄清楚如何做这么简单的事情有点像寻宝。云功能文档似乎建议查看管理SDK:“您可以通过DeltaDocumentSnapshot界面或管理SDK进行CloudFirestore更改。”https://firebase.google.com/docs/functions/firestore-eventsAdminSDK建议编写以下代码行来获取客户端。但是哦,不,它不会解释客户。它将让我们在文档的其他地方进行徒劳的追逐。vardefaultFirestore=admin.firestore();“如果

javascript - 在构造函数中调用异步函数。

getUser是一个异步函数?如果需要更长的时间来解决?它是否总是会在我的someotherclass中返回正确的值。classIdpServer{constructor(){this._settings={//someidentityserversettings.};this.userManager=newUserManager(this._settings);this.getUser();}asyncgetUser(){this.user=awaitthis.userManager.getUser();}isLoggedIn(){returnthis.user!=null&&!th

javascript - Firebase Function 从其他文件导入函数 - javascript

我正在使用javascript构建firebase函数。现在我有很多内部调用函数,我打算将这些函数移动到不同的文件中,以避免index.js变得非常困惑。下面是当前的文件结构:/functions|--index.js|--internalFunctions.js|--package.json|--package-lock.json|--.eslintrc.json我想知道:1)如何从internalFunctions.js中导出函数并将其导入到index.js中。2)如何从index.js调用internalFunctions.js函数。我的代码是用JavaScript编写的。已编辑

javascript - 箭头函数与 Javascript 函数的行为差异

这个问题在这里已经有了答案:Are'ArrowFunctions'and'Functions'equivalent/interchangeable?(4个答案)关闭4年前。我想了解普通函数与箭头函数的行为。箭头函数:functionarrowFunc(){return()=>arguments}console.log(arrowFunc(1,2,3)(1))正常功能functionnormalFunc(){returnfunction(){returnarguments}}console.log(normalFunc(1,2,3)(1))这两个结果预计是相同的,但看起来上面定义的arr

javascript - 函数和无状态组件之间的区别?

下面的两个示例显然产生了完全相同的代码。示例1(React子项):constChild=({item:{startedAt,count}})=>({startedAt}{count})constParent=items=>{return({items.map((item,index)=>())})}exportdefaultParent示例2(子函数):constchild=({id,startedAt,count})=>({startedAt}{count})constParent=items=>{return{items.map(child)}}exportdefaultParen

javascript - 如何设置一个对象函数等于另一个

这个问题在这里已经有了答案:Self-referencesinobjectliterals/initializers(30个答案)关闭4年前。假设我有以下对象:letobj={childone:(value)=>{returnvalue+1;},childtwo:(value)=>{returnvalue+3;},childsingle:(value)=>{returnvalue+1;}};有没有什么方法可以在同一声明中将obj.childsingle设置为等于obj.childone?我试图在对象声明中实现childsingle=childone。我还尝试根据重复的建议答案使用get

javascript - 为什么我不能在类函数上使用扩展运算符?

我是JavaScript新手。只是关于在类函数上使用扩展运算符的问题。一个例子:letpersonA={name:"Tom",testFunction:function(){//...}};letnewArray=[];newArray.push({...personA});console.log(newArray);输出是:[{name:'Tom',testFunction:F}]但是如果我使用一个类,比如:classPerson{constructor(name){this.name=name;}testFunction(){}}letpersonA=newPerson("Tom"

javascript onclick,匿名函数

我是一名初级JavaScript程序员。我正在尝试创建类似于Lightbox2的东西,但要简单得多。我想自己从头开始做的唯一原因是我可以学习。但是,我一直停留在显示图像的最后一个关键部分。我相信问题出在我尝试使用onclick并分配给匿名函数的地方:elem[i].onclick=function(){liteBoxFocus(imgSource,imgTitle);返回假;};。如果您运行我的代码并尝试单击谷歌Logo,它会显示雅虎Logo和标题,而不是谷歌的Logo和标题。但是,当您单击雅虎Logo时,它工作正常,因此匿名函数似乎只适用于最后一个循环。提前致谢!!!为了方便起见,我