jjzjj

argument

全部标签

javascript - react : how to pass arguments to the callback

我的React组件中有一个元素列表,我希望它们是可点击的。单击时我调用一些外部函数在参数中传递项目ID:render(){return({this.props.items.map(item=>({doSomething(item.id)}>))})}此代码有效,但它有一个很大的性能缺陷:每次调用render时都会创建许多新的匿名函数。如何在此处传递doSomething函数作为引用,同时仍然能够为其提供item.id? 最佳答案 您可以使用data-attributes,在使用相同功能的同时为每个项目设置正确的id:function

javascript - 为什么 apply with too many arguments 抛出 "Maximum call stack size exceeded"?

在Chrome和Node中,以下代码会抛出错误:functionnoop(){}vara=newArray(1e6)//Array[1000000]noop.apply(null,a)//UncaughtRangeError:Maximumcallstacksizeexceeded我明白为什么将100万个参数传递给一个函数可能是个坏主意,但谁能解释为什么错误是超出最大调用堆栈大小,而不是更相关的错误?(如果这看起来很无聊,原来的情况是Math.max.apply(Math,lotsOfNumbers),这是一种从数组中获取最大数的不合理方法。) 最佳答案

javascript - 甜蜜警报 : how pass argument to callback

我正在使用javascript警报库sweetalert我的代码是:functionfoo(id){swal({title:"Areyousure?",text:"Youwillnotbeabletorecoverthisimaginaryfile!",type:"warning",showCancelButton:true,confirmButtonColor:"#DD6B55",confirmButtonText:"Yes,deleteit!",closeOnConfirm:false},function(){swal("Deleted!","Yourimaginaryfileha

javascript - 对象上的意外 "arguments"属性

在下面,第二个和第三个控制台输出似乎是矛盾的:functiontest(){console.log(arguments);//->["my","arguments"]console.dir(this);//->testfunctionwithargumentspropertysettonullconsole.log(this.arguments);//->["my","arguments"]}test.call(test,'my','arguments');根据我的评论,检查this上的arguments属性显示null,同时记录this.arguments明确显示["my","arg

javascript - 新 ECMA5 Javascript 标准中的 argument.callee.name 替代方案

这个问题在这里已经有了答案:Alternativetoarguments.callee(2个答案)关闭8年前。我正在努力将一些旧代码移植到“严格模式”,ECMA5标准中的argument.callee和类似的argument.caller等有哪些替代方案?添加信息:我没有说明为什么我需要argument.caller/callee。我正在移植的代码正在使用assert.ok(elemNode,arguments.callee.name+":Entity-"+entityId+"hasbeenfound");如果它是简单的递归,我可以使用functionname(){...functio

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 - Jade : escape html in mixin argument

我尝试过的:mixinsimpleDivInject(text)divh1#{text}mixinsimpleDivInject("lineonelinetwo")期望的结果lineonelinetwo实际结果lineone<br/>linetwo我怎样才能达到预期的结果。我已经尝试了更多的东西(例如将字符串存储在varect中),但到目前为止没有成功。 最佳答案 其实我只是想通了。在这里回答希望对其他人有帮助。转义不是发生在mixin参数系统中,而是发生在vinillajade系统中,所以:mixinsimpleDiv

javascript - Arguments 对象是否泄漏?

假设我有这个草率模式函数,它(出于某种奇怪的原因)将其arguments对象返回给调用者:functionexample(a,b/*...*/){varc=//someprocessingreturnarguments;}存储调用结果(vard=example();)会阻止example的变量环境(包含a,b、c等)免于被垃圾回收?Argumentsobject的内部setter和getter可能仍然引用它,就像从闭包返回的函数一样。演示:functionexample(a,b){varc=Array(1000).fill(0);//somelargeobjectreturn{args

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 - ES5 "strict"和 arguments.callee

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whywasthearguments.callee.callerpropertydeprecatedinJavaScript?在ES5严格模式(即“usestrict”)中,引用当前函数的arguments.callee变量不再可用。对于递归函数,使用函数自己的名称显然是明智的。然而,有时我可能想使用arguments.callee的属性(即.length、.prototype)而不必使用名称当前功能。谁能解释通过删除它(据称)解决了哪些明显的问题?