草庐IT

function_date-add

全部标签

javascript - react : 'this.state' is undefined inside a component function

我在组件内的函数中访问this.state时遇到问题。我已经找到了this关于SO的问题并将建议的代码添加到我的构造函数中:classGameextendsReact.Component{constructor(props){super(props);...this.state={uid:'',currentTable:'',currentRound:10,deck:sortedDeck};this.dealNewHand=this.dealNewHand.bind(this);this.getCardsForRound=this.getCardsForRound.bind(this)

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 - Jade : load external javascript and call function

我正在学习Express/Node/Jade,现在我想在Jade文件中包含一个来自公共(public)文件夹的javascript文件,只用于该页面。例如,在jade文件中我输入:script(src='/javascripts/test.js')在test.js里面我有一个函数functioncheck_test(){return"It'sworking!"}然后我尝试通过以下方式调用Jade中的函数-vartest_response=check_test()比我得到的错误说“undefinedisnotafunction”和test.js根本没有加载。显然Jade不会加载文件,它们

javascript - Meteor:为什么将 function() { } 切换为 () => { } 会丢失我的数据上下文?

所以我正在试验ES6,安装了grigio:babel包,并开始检查我的es5代码并在遇到问题时将其更新为一些新的ES6语法。最初我的模板助手看起来像这样:Template.exampleTemplateName.helpers({exampleHelper:function(){//returnsanarrayfromMongoCollection}});在Blazeeach循环中使用{{#eachexampleHelper}}{{/each}}如您所料,我在这个事件循环中的元素的所有事件处理程序都可以访问exampleHelper通过this关键字。this.exampleField

javascript - CSS 下拉菜单 : Add delay on mouse out

我在下面使用CSS和HTML制作了下拉菜单:MainMenu.menu{float:left;background:#CCC;margin:0px;padding:0px;}.menuli{position:relative;float:left;width:180px;padding:5px0px;list-style:none;}.menuli:hover{background:#999;}.menuul{display:none;position:absolute;background:#CCC;padding:0;margin:5px000;}.menuulliul{left:

Javascript:typeof 说 "function"但它不能作为函数调用

这次我真的对Javascript很困惑:varx=Array.prototype.concat.call;typeofx;//functionx();//UncaughtTypeError:xisnotafunction这到底是怎么回事?如果有帮助,我还注意到:x([1,2],[3,4])也不行toString也认为是一个函数:Object.prototype.toString.call(x);//"[objectFunction]"Array.prototype.concat.apply也会发生这种情况。当它被强制作为一个表达式时它也不起作用:(0,Array.prototype.c

javascript - 未捕获的类型错误 : lang is not a function

这个问题在这里已经有了答案:JSfunctionnamed`animate`doesn'tworkinChrome,butworksinIE(3个答案)关闭6年前。在我的HTML中,我在script标签中定义了lang函数并添加了“TestFire!”单击时必须调用lang的按钮:TestingFunctionsfunctionlang(){alert("Hello,World!It'sJavaScriptthistime");}但是,如果我点击按钮,我会得到这个错误:UncaughtTypeError:langisnotafunction但是,如果我将函数名称从lang更改为任何其他

javascript - 为什么 1 * new Date() 而不是 GA 片段中的 new Date().getTime()?

我正在插入GAsnippet在我的TypeScript代码中看到这个:i[r].l=1*newDate();TypeScript编译器提示newDate()必须是数字或任何,但不是日期。我把这个变成了这个:i[r]['l']=newDate().getTime();这导致相同的结果。如果优先考虑的是减小尺寸,那么我发现这更紧凑,结果相同:i[r]['l']=+newDate();我不知道为什么使用带有隐式转换的智能变体。是否有什么我不明白的隐藏内容,或者只是人们想要看起来更聪明?是为了缩短长度吗? 最佳答案 Isthereanyth

javascript - 类型错误 : scrollIntoView is not a function

我是react-testing-library/jest的新手,正在尝试编写测试以查看路由导航(使用react-router-dom)是否正确执行。到目前为止,我一直在关注README还有这个tutorial关于如何使用。我的一个组件在本地函数中使用了scrollIntoView,这导致测试失败。TypeError:this.messagesEnd.scrollIntoViewisnotafunction45|46|scrollToBottom=()=>{>47|this.messagesEnd.scrollIntoView({behavior:"smooth"});|^48|}49|

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