草庐IT

parameter-passing

全部标签

google-maps-api-3 - Javascript 将参数传递给回调或在 DistanceMatrixStatus 中设置变量值

我一直在玩Google的DistanceMatrixService。下面的代码有效,但是,如何将另一个参数传递给回调函数或从回调函数中获取其中一个值?例如:我有两个div,我想在(Results1和Results2)中显示不同的结果,所以我想我需要要么将另一个值传递给GoogleMapDistance函数,例如GoogleMapDistance(YourLatLong,DestLatLong,TheDiv)或者能够在回调外部获取ResultStrdocument.getElementById("Results1").innerHTML=ResultStr;或者将innerHTM设置为函

javascript - 表达 : typescript: Argument of type 'typeof <express.Router>' is not assignable to parameter of type 'RequestHandlerParams'

我将expressjs与最新的typescript定义文件和来自https://github.com/DefinitelyTyped/DefinitelyTyped的typescript2.3.4一起使用.我定义了一个路由器,并希望按照官方4.x文档(app.use('/calendar',router);)中的说明从子路径使用它,但出现以下错误Error:/Users/matthias/Documents/privateworkspace/universal/src/server/server.ts(161,34):Argumentoftype'typeof"/Users/matth

javascript - Sequelize 更新不再起作用 : "Missing where attribute in the options parameter passed to update"

TheofficialAPIdocumentation建议像这样使用Model.update:vargid=...;varuid=...;varvalues={gid:gid};varwhere={uid:uid};myModel.update(values,where).then(function(){//updatecallback});但这给了我:“传递给更新的选项参数中缺少where属性”。文档还提到这种用法已被弃用。看到这个错误让我想,他们已经改变了它。我做错了什么? 最佳答案 显然,文档还没有更新。但是表的where行t

javascript - 如何通过 "setInterval"kick ass pass scope

我目前想知道是否有比通过参数'e'将this范围传递给lambda函数然后将其传递给'funkyFunction更好的解决方案'使用call()方法setInterval(function(e){e.funkyFunction.call(e)},speed,this)(撇开小问题:我一直在阅读有关javascript中内存泄漏的内容。lambda函数如何影响我的内存?首先定义它是否更好,如vari=function(e)。..然后将其作为参数传递给setInterval?) 最佳答案 我的情况可能有点不同,但我是这样做的:varse

javascript - 在 Javascript 中允许命名参数或位置参数

我怎样才能让函数接受任一个命名参数(foo({a:'hello',b:'itisme'}))或位置参数(foo('hello','itisme'))?我知道可以通过将对象传递给函数来模拟命名参数:functionfoo(options){options=options||{};vara=options.a||'peanut';//whateverdefaultvaluevarb=options.b||'butter';//whateverdefaultvalueconsole.log(a,b);}//ES6allowsautomaticdestructuringfunctionfoo(

javascript - typescript 键盘事件 : argument of type 'Event' is not assignable to parameter of type 'KeyboardEvent'

即使代码运行完美,我也会出现以下错误:"TS2345:Argumentoftype'Event'isnotassignabletoparameteroftype'KeyboardEvent'.Property'altKey'ismissingintype'Event'."//InaClasspubliclistenTo=(window:Window)=>{['keydown','keyup'].forEach(eventName=>{window.addEventListener(eventName,e=>{this.handleEvent(e);//{const{key}=event

javascript - Vuex + VueJS : Passing computed property to child is undefined

我正在阅读这个documentationonVuecomponents,但使用Vuex数据作为我的组件属性。在这个例子中,如果country_id在data方法中,它工作正常。但是当country_id是一个从Vuexstore返回数据的计算属性时,子组件的internalValue总是被初始化为undefined。我做错了什么?父组件:exportdefault{computed:{country_id(){returnthis.$store.state.user.country_id}},mounted:function(){this.$store.dispatch('user/l

javascript - 未捕获的类型错误 : Failed to execute 'observe' on 'MutationObserver' : parameter 1 is not of type 'Node'

所以我下面的代码在jsfiddle中独立运行。但出于某种奇怪的原因..在将它推送到实时服务器后,我一直收到此错误:/我无法弄清楚为什么......错误:mycodewitherror.js:23UncaughtTypeError:Failedtoexecute'observe'on'MutationObserver':parameter1isnotoftype'Node'.js:$(document).ready(function(){//Thebelowcollectsuserloginname,newlogindateandtime,andprevioususeURLvarelem

javascript - JS函数声明: curly brace object assigned with an empty object in parameter declaration

这是代码,exportfunctioncreateConnect({connectHOC=connectAdvanced,mapStateToPropsFactories=defaultMapStateToPropsFactories,mapDispatchToPropsFactories=defaultMapDispatchToPropsFactories,mergePropsFactories=defaultMergePropsFactories,selectorFactory=defaultSelectorFactory}={}){...}函数参数声明中的{connectHOC=

javascript - 中级 JavaScript : assign a function with its parameter to a variable and execute later

我有一个JavaScript函数:functionalertMe($a){alert($a);}我可以这样执行:alertMe("Hello");我想做的是将带有"Hello"参数的alertMe("Hello")赋给一个变量$func,然后稍后可以通过执行$func();之类的操作来执行此操作。 最佳答案 我想添加评论作为答案代码//definethefunctionfunctionalertMe(a){//returnthewrappedfunctionreturnfunction(){alert(a);}}//declaret