jjzjj

argument-passing

全部标签

javascript - JS : Get inner function arguments in asynchronous functions and execute callback

我尝试编写返回异步函数的所有结果的函数,并执行一个回调,将其插入数组并记录每个异步函数的结果。作为一个服务员,当所有的菜都吃完了就端上来。我不明白如何获得应该作为结果返回的子参数。任务代码和我不工作的解决方案如下:任务:vardishOne=function(child){setTimeout(function(){child('soup');},1000);};vardishTwo=function(child){setTimeout(function(){child('dessert');},1500);};waiter([dishOne,dishTwo],function(res

javascript - TypeError [ERR_INVALID_ARG_TYPE] : The "original" argument must be of type Function. 接收类型未定义

在下面的代码中,我得到了这个错误:TypeError[ERR_INVALID_ARG_TYPE]:The"original"argumentmustbeoftypeFunction.Receivedtypeundefinedconstsqlite3=require('sqlite3').verbose();constutil=require('util');asyncfunctiongetDB(){returnnewPromise(function(resolve,reject){letdb=newsqlite3.Database('./project.db',(err)=>{if(e

javascript - Babel/Karma/Chai 给出 TypeError : 'caller' , 'callee' 和 'arguments' properties may not be accessed on strict mode functions

我无法弄清楚为什么这个测试没有通过。varexpect=require('chai').expect;describe('HelloComponent',function(){it('passesaquitesimpletest',function(){expect(1+4).to.equal(5);});});产生这个错误:DEBUG[web-server]:serving:/Users/ivan/dev/react-starter/node_modules/karma/static/context.htmlDEBUG[web-server]:serving(cached):/Use

javascript - 将 'arguments' 传递给 'apply()' 是否安全

假设我有以下代码(完全没用,我知道)functionadd(a,b,c,d){alert(a+b+c+d);}functionproxy(){add.apply(window,arguments);}proxy(1,2,3,4);基本上,我们知道apply需要一个数组作为第二个参数,但我们也知道arguments不是一个正确的数组。代码按预期工作,所以可以肯定地说我可以将任何类似数组的对象作为apply()中的第二个参数传递吗?以下内容也可以使用(至少在Chrome中):functionproxy(){add.apply(window,{0:arguments[0],1:argumen

javascript - 替代 arguments.callee

我有一个EventListener可以监听整个文档并记录击键,但我想在满足某些条件时删除此监听器。以下是我的代码片段:document.addEventListener('keyup',function(e){varletter_entered=String.fromCharCode(e.keyCode).toLowerCase();player.makeGuess(letter_entered);if(player.win_status===true||player.lose_status===true){document.removeEventListener('keyup',ar

javascript - 避免 React 中的内联函数 : How to bind functions with arguments?

我正在尝试关注no-bindReact使用他们推荐的ES6类模式的规则:classFooextendsReact.Component{constructor(){super();this._onClick=this._onClick.bind(this);}render(){return(Hello!);}_onClick(){//Dowhateveryoulike,referencing"this"asappropriate}}但是,当我需要将参数传递给_onClick时,需要更改什么?我试过类似的方法:import{someFunc}from'some/path';classFoo

javascript - 加密错误 : data and hash arguments required

我收到一个bcrypt错误,指出需要数据和哈希参数,引用我的routes.js文件中的第44行。据我所知,我正在传递该信息:bcrypt.compare的第一个参数是用户输入的密码,第二个是从数据库中检索到的散列密码。我做错了什么?bcrypt.compare(req.params.password,user.password,function...routes.js'usestrict'varexpress=require('express');varrouter=express.Router();varUser=require('../app/models/user');//pas

javascript - 弃用警告 : Collection#find: pass a function instead

我是node.js的新手,我目前正在使用discord.js制作Discord机器人。一旦使用了任何bot命令,控制台就会打印出DeprecationWarning。例如:(node:15656)DeprecationWarning:Collection#find:passafunctioninstead(node:15656)有时是另一个数字,几乎总是在变化。这就是我的代码的样子(只有一个命令,我有多个命令,但所有命令都出现此错误):constbotconfig=require("./botconfig.json")constDiscord=require("discord.js")

javascript - react : Passing props to function components

我有一个关于props和函数组件的看似微不足道的问题。基本上,我有一个容器组件,它在用户单击按钮触发的状态更改时呈现模态组件。模态是一个无状态函数组件,其中包含一些需要连接到容器组件中的函数的输入字段。我的问题:当用户与无状态Modal组件内的表单字段交互时,如何使用父组件内的函数来更改状态?我是否错误地传递了Prop?容器exportdefaultclassLookupFormextendsComponent{constructor(props){super(props);this.state={showModal:false};}render(){letclose=()=>this

javascript - JS传单: How to pass (Geo-)json ID to on click event?

我的djangoweb应用程序应该执行以下操作:将Geojson对象传递给View,使用传单映射点,并在用户单击点标记时显示一些附加信息。我不太熟悉js,所以我无法将正确类型的数据绑定(bind)到click事件。这是一个示例geojson对象。如何使用我的click事件访问“id”?vargeojsonFeature={'geometry':{'type':'MultiPoint','coordinates':[[4.939,52.33],[4.9409,52.33]]},'type':'Feature','properties':{'id':'52','popupContent':