草庐IT

map-function

全部标签

使用 `new Function()` 优化 Javascript

在阅读文档时,我发现了一个可以大大提高javascript性能的简单优化。原代码:functionparseRow(columns,parser){varrow={};for(vari=0;i优化代码:varcode='return{\n';columns.forEach(function(column){code+='"'+column.name+'":'+'parser.readColumnValue(),\n';});code+='};\n';varparseRow=newFunction('columns','parser',code);在这里找到:https://github

javascript - `Function` 创建的这些函数有什么区别?

1.varf=newFunction("a","b","returna+b")2.varf2=Function("a","b","returna+b")f和f2都是匿名函数。f(1,2)和f2(1,2)都返回3。那么两者之间有什么实际的内部差异吗?Function是否在内部返回一个函数对象?与使用Function作为构造函数newFunction(...)的区别? 最佳答案 来自ECMAScript5.1specs:WhenFunctioniscalledasafunctionratherthanasaconstructor,itc

javascript - Javascript如何比较 map 的键

我在node.js应用程序中使用JavascriptES6特性:classpairKey{constructor(x_pos,y_pos){this._X=x_pos;this._Y=y_pos;}getx(){returnthis._X;}setx(x_pos){this._X=x_pos;}gety(){returnthis._Y;}sety(y_pos){this._Y=y_pos;}varallElem=newMap();allElem.set(newpairKey(1,2),'a');allElem.set(newpairKey(2,3),'b');console.log(a

javascript - 重组 "withReducer": justification of async reducer function call

我正在使用withReducerHOC并注意到这种行为:例如,在点击处理程序上调用它:importReactfrom'react'import{withReducer}from'recompose'import{compose}from'ramda'exportdefaultcompose(withReducer('state','dispatch',(state,{value})=>{console.log(value)return{...state,value}},{value:'zero'}))((props)=>{const{dispatch,state}=props,onCl

javascript - 分配后无法将文档添加到 lunr 索引(TypeError : idx. add is not a function)

我正在尝试创建一个lunr索引并能够在分配后向其中添加文档。这是我正在尝试做的稍微简化的版本:vardocuments=[{'id':'1','content':'hello'},{'id':'2','content':'world'},{'id':'3','content':'!'}];varidx=lunr(function(){this.ref('id');this.field('content');});for(vari=0;i这给我以下错误:TypeError:idx.add不是一个函数。我见过多个tutorials说这是你应该能够做到的。如果我在分配idx时添加文档,它只对

javascript - 错误 : "Cannot find module" while running firebase cloud function

constfunctions=require('firebase-functions');varnodemailer=require('nodemailer');//constexpress=require('express');vartransporter=nodemailer.createTransport('smtps://username@gmail.com:password5@smtp.gmail.com');exports.sendMail=functions.https.onRequest((req,res)=>{varmailOptions={to:'receiver@

javascript - Cloud Functions - Cloud Firestore 错误 : can't get serverTimestamp

CloudFunctions-CloudFirestore错误:无法获取服务器时间戳constadmin=require('firebase-admin');exports.userlog=functions.firestore.document('user/{userId}').onUpdate((change,context)=>{constdb=admin.firestore();//vartimestamp=db.FieldValue.serverTimestamp();vartimestamp=db.ServerValue.TIMESTAMP;...returndb.coll

javascript - 有没有办法将 map 的所有条目设置为一个值

我有一个数组,我想将其用作map的键并将每个值设置为true。除了在我的数组上使用forEach循环来设置每个条目之外,还有其他方法吗?这就是我现在的做法:constlist=[0,1,2,3];constmyMap=newMap();list.forEach(element=>myMap.set(element,true));有没有更好的办法? 最佳答案 一种更简洁、更实用的方法是将列表的map作为参数传递给map:constlist=[0,1,2,3];constmyMap=newMap(list.map(key=>[key,t

javascript - 视觉 : default value for prop function

有什么方法可以为具有函数类型的prop设置默认函数吗?props:{clickFunction:{type:'Function'default:????}} 最佳答案 是的:Vue.component('foo',{template:'{{num}}',props:{func:{type:Function,default:()=>1,},},data(){return{num:this.func()}}})newVue({el:'#app',}); 关于javascript-视觉:def

javascript - 如何更改 Google Maps API v3 中的 MapTypeid?

当用户点击标记时,我需要将map类型从RoadMap更改为Hybrid(它已经自动缩放并居中)我在Google3.2的API文档中找不到任何关于如何做到这一点的内容。任何帮助将不胜感激! 最佳答案 您需要在您的map上调用setMapTypeId对象:setMapTypeId(mapTypeId:MapTypeId)哪里mapTypeId是混合的。 关于javascript-如何更改GoogleMapsAPIv3中的MapTypeid?,我们在StackOverflow上找到一个类似的问