草庐IT

function-prototypes

全部标签

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 - Cloud Functions for Firebase 超时

用于获取数据库数据的简单云功能无法正常工作。getusermessage()不工作错误:Functionexecutiontook60002ms,finishedwithstatus:'timeout'用于获取数据库结果的Index.JS。constfunctions=require('firebase-functions');constadmin=require('firebase-admin');admin.initializeApp(functions.config().firebase);constcors=require('cors')({origin:true});//Ta

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 - JQuery JavaScript 设计 : Self Executing Function or Object Literal?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我很好奇在构造封装代码块时是否有任何与JQuery相关的最佳实践。通常,当我构建一个页面时,我喜欢将该页面中使用的函数封装在一个对象中。这允许我在构建应用程序时进行一些封装。没有什么比看到带有一堆这样的JavaScript文件更让我讨厌的了functiondoSomethingOnlyRelevantOnThisPage(){//dosomestuff}这会导致设计困惑,并且没有很好地封装

javascript - Prototype vs. Not,有什么好处?

这里我做了两个对象;一个在构造函数中创建访问器方法,另一个在原型(prototype)中创建。为什么人们会选择其中之一而不是另一个?functionspy1(name){this.name=name;varsecret;this.setSecret=function(message){secret=message;};this.getSecret=function(){returnsecret;};}functionspy2(name){this.name=name;this.secret;/*(seecomment)was:varsecret;*/}spy2.prototype.se

javascript - react : Passing props to function components

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

javascript - 如何在异步/等待语法中使用 Promise.prototype.finally()?

实际上我的主要问题是在async/awaitES8语法中使用Promise.prototype.catch(),毫无疑问是Promise。prototype.then()存在于async/await语法的本质中。我搜索了关于在async/await中使用Promise.prototype.catch()并找到了这个:async()=>{try{constresult1=awaitfirstAsynchronousFunction();constresult2=awaitsecondAsynchronousFunction(result1);console.log(result2);}c

javascript - Array.prototype.slice 奇怪的行为

考虑这段代码,每行末尾都有控制台输出:functionwhatever(){console.log(arguments)//{'0':1,'1':2,'2':3,'3':4,'4':5}console.log(Array.prototype.slice.call(arguments))//[1,2,3,4,5]console.log(Array.prototype.slice.call({'0':1,'1':2,'2':3,'3':4,'4':5}))//[]}whatever(1,2,3,4,5)为什么第三个console.log输出一个空数组? 最佳答案

javascript - Materialise Cssmodal showing $(..)leanmodal is not a function 错误

当我尝试使用以下代码创建一个物化cssmoal时,出现错误。ResetWarning!Doyoureallywanttoreset?YesNo$(document).ready(function(){//the"href"attributeof.modal-triggermustspecifythemodalIDthatwantstobetriggered$('.modal-trigger').leanModal();});ErrorImage我试过了thisquestion还有。 最佳答案 也许您正在使用Materialise0.

javascript - 这个 Prototype 到 JQuery 的端口是否正确?

我们的代码会在用户闲置一段时间后运行。(doStuff重置倒计时)原型(prototype)中的现有代码:Event.observe(window,'mousemove',function(){doStuff();});Event.observe(window,'scroll',function(){doStuff();});Event.observe(window,'click',function(){doStuff();});Event.observe(window,'focus',function(){doStuff();});Event.observe(window,'blur