jjzjj

parameter

全部标签

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

javascript - Handlebars : What is the best way to pass multiple parameters to a registerHelper function?

我正在使用Handlebars在表格中呈现数据。其中一个数据项需要处理,它会考虑一些参数以提供结果。模板化文本示例:{{getOutputByParametersparam1=DataFieldName1param2=DataFieldName2}}相应的registerHelper会写成:var__this=this;Handlebars.registerHelper('getOutputByParameters',function(params){__this.getOutputByParameters(params.hash.param1,params.hash.param2)}

javascript - 无法在 'requestAnimationFrame' : The callback provided as parameter 1 is not a function. 上执行 'Window'

不确定我在这里做错了什么......window.requestAnimFrame=function(){return(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(/*function*/callback){window.setTimeout(callback,1000/60);});}();

javascript - AngularJS fn is not a function error using $timeout with a function with parameters 错误

我正在制作一个您可以编辑文本的网页,在您停止输入1秒后,它会自动保存您输入的内容。目前我正在研究$timeout的细节。当我调用没有参数的update方法时,它可以正常工作,但是当我使用参数调用它时,我得到错误:Error:fnisnotafunction$TimeoutProvider/this.$get为什么我在执行以下操作时会收到此错误:timeout=$timeout(update(element,content),1000);但不是当我这样做的时候:timeout=$timeout(update,1000);显然我需要将参数传递给更新方法,因为我需要知道要更新什么。debou

javascript - 为什么 push 显示 argument of type 'any[]' is not assignable to parameter of type 'never' 错误?

在这段代码中我得到了休闲错误:Argumentoftype'any[]'isnotassignabletoparameteroftype'never'varmarkers:[];this.Getlapoints(this.map.getCenter(),500000).then(data=>{for(varkeyindata){Leaflet.marker(data[key].location,//{icon:greenIcon}).addTo(this.map).bindPopup(data[key].caption);//markers.push(data[key].locatio

javascript - Lint 警告 : parseInt missing radix parameter

这个问题在这里已经有了答案:JSLintsays"missingradixparameter"(11个答案)关闭9年前。我有以下代码给出标题中描述的警告:year:parseInt(dateParts[0]),......................^非常感谢任何帮助

javascript - 方法参数 : destructuring + keeping original parameter (ReactJS component)

这个问题在这里已经有了答案:ES6destructuringfunctionparameter-namingrootobject(5个答案)关闭3年前。有没有办法实现方法参数解构,又能获取方法参数。在具有无状态组件的React应用程序的上下文中,我希望能够替换constMyComponent=(props)=>{const{prop1,prop2}=props;return()}使用更简洁的语法,如constMyComponent=(props:{prop1,prop2})()有没有类似的语法可用?

javascript - Angular : Pass additional parameters to chained promises

我想链接一些由服务返回的promise。只要某些返回promise的方法不需要额外的参数,这就可以工作。这是我的例子:varfirst=function(){vard=$q.defer();$timeout(function(){d.resolve("firstresolved")},100)returnd.promise;};varsecond=function(val){console.log("valueofval:",val);vard=$q.defer();$timeout(function(){d.resolve("secondresolved")},200)returnd

javascript - 如何删除使用闭包添加的 EventListener?

这基本上是一个后续问题:Can'tpasseventtoaddEventListener:closureissue.我几乎阅读了所有相关问题,但找不到答案。下面的函数是在一个循环中执行的,其中参数是从数据数组中提取的。使用此功能,我可以将不同的/新的参数传递给事件监听器的每个实例。outerfunction允许将参数的值封装在闭包中,以便实际值可用,而不仅仅是对持有者的引用。此外,传递事件函数将事件传递给响应函数。最后,responsefunction具有所有适当的信息以响应点击事件。这很好用。问题是,我不知道以后如何删除事件监听器。我已经尝试了我能想到的一切。请帮忙。我怎样才能:re

javascript - 在 json 数组中使用变量作为标识符

我想知道是否可以使用分配的变量作为json数组中的标识符。当我尝试这样做时,我得到了一些意想不到的结果:(代码精简,参数传递方式不同)varparameter='animal';varvalue='pony';Util.urlAppendParameters(url,{parameter:value});Util.urlAppendParameters=function(url,parameters){for(varxinparameters){alert(x);}}现在警报弹出窗口显示:“参数”而不是“动物”。我知道我可以使用不同的方法(创建一个数组并在新行上分配每个参数),但我想保