草庐IT

map-function

全部标签

javascript - 调用 Function.prototype.method() 时 TypeError : this. prototype is undefined

我正在读《Javascript:好的部分》这本书。现在我正在阅读有关增强类型的章节:Function.prototype.method=function(name,func){this.prototype[name]=func;returnthis;};更新:为什么下面的代码不起作用?js>Function.prototype.method("test",function(){print("TEST")});typein:2:TypeError:this.prototypeisundefined但是下面的代码没有问题:js>Function.method("test",function

javascript - 使用 `new Function` 和性能问题

我正在通过AJAX加载一个脚本文件,并运行它的内容,我正在这样做:newFunction('someargument',xhr.responseText)(somevalue);但是,根据MDN:FunctionobjectscreatedwiththeFunctionconstructorareparsedwhenthefunctioniscreated.Thisislessefficientthandeclaringafunctionandcallingitwithinyourcode,becausefunctionsdeclaredwiththefunctionstatement

关于 Python 'map()' 函数的 Javascript 与 Python

在Python中有一个名为map的函数,它允许你去:map(someFunction,[x,y,z])并继续应用该列表功能。是否有与此功能等效的javascript?我现在刚开始学习Python,虽然有人告诉我javascript是函数式语言,但我可以看出我一直在使用非函数式javascript风格进行编程。作为一般规则,javascript能否像Python一样有效地用作函数式语言?它有没有像上面的map函数一样的技巧?我也刚刚开始学习SML类(class),想知道我学到的知识有多少也适用于javascript。 最佳答案 当然!

javascript - angular-google-maps 现在在开始时隐藏时可以正确显示

本地图开始使用ng-show/ng-hide隐藏时,一旦可见就无法正确显示。标准map也有同样的问题,只有我们可以向它发送调整大小,因为我们可以访问map对象。这是一个以隐藏map开始的示例。该按钮切换map的可见性。.angular-google-map-container{width:100%;height:100px;}.mymap{width:100%;height:100px;}ToogleMapvarapp=angular.module("app",["google-maps"]);app.controller("myCtrl",function($scope,$timeo

javascript - 我们如何在 google map api 中通过 javascript 设置标记标签内容?

我正在使用此代码此代码更改googlemapapi中标记标签的标签文本。但是这段代码不起作用。varmarker=newMarkerWithLabel({position:latlng,draggable:true,raiseOnDrag:true,map:map,labelContent:textVal,labelAnchor:newgoogle.maps.Point(22,0),title:""+textCount,labelClass:"someClass"+textCount,icon:{}});marker.setLabelContent("sdda");谁能告诉我我的代码有

javascript - Mongoose - TypeError : object is not a function

我正在尝试将Mongoose模型从我的model/user.model.js文件导出到我的服务器目录中的server.js文件。模型/user.model.jsvarmongoose=require('mongoose');varSchema=mongoose.Schema();varUserSchema=newSchema({instagramId:{type:String,index:true},email:{type:String,unique:true,lowercase:true},password:{type:String,select:false},userName:St

javascript - Lodash - 从 Map 方法有条件地返回对象

我想遍历一个数组,运行一个计算,如果结果的条件为真,则返回一个新对象。_.filter(...)在这里不起作用,因为迭代器函数必须返回true或false。_.map(people,function(person){varage=calculateAge(person.birthDate);if(age>50){return{person:person,age:age};}});我已经尝试搜索所有内容,包括文档,但我还没有找到一种很好的方法。 最佳答案 听起来你可能想要reduce而不是map:varnewArray=_.reduc

javascript - 如何在javascript中动态创建一个包含值数组的 map

我有这个需求。根据函数中传递的参数数量,我需要在map中创建那么多条目。假设我有一个函数myfunc1(a,b,c),我需要一个键为“a”、“b”和“c”的映射,并且每个键可以有多个值。但问题是我事先不知道这些键会有多少值。当值出现时,我需要将它们添加到与映射中的匹配键对应的值列表中。我如何在javascript中执行此操作?我找到了如下静态答案。但我想动态地做到这一点。我们可以使用push方法吗?varmap={};map["country1"]=["state1","state2"];map["country2"]=["state1","state2"];

javascript - 为每个订阅者评估的 rxjs map 运算符

为什么map运算符针对每个订阅者而不是一次进行评估?constobs1=Rx.Observable.interval(1000).take(1).map((x,i)=>{console.log(i+1+':1map')return'obs1';})constobs2=Rx.Observable.interval(1300).take(1).map((x,i)=>{console.log(i+1+':2map')return'obs2';})constobs3=Rx.Observable.interval(1700).take(2).map((x,i)=>{console.log(i+1

javascript - 使用 lodash,为什么 flow 中的 map 方法不起作用?

我有一个用户对象,我正在尝试对其使用lodashmap()方法以使其仅返回userId,同时使用currentUserId过滤掉任何用户.我想避免使用chain()因为它会拉入整个库,所以看起来flow()方法是完美的,但它没有映射到数组身份证。import{map,filter,flow,}from'lodash';constusers={123:{uid:123},456:{uid:456}};constcurrentUserId=123;constuserIds=flow(map(user=>user.uid),filter(userId=>userId!==currentUse