草庐IT

send_this_email

全部标签

javascript - 在 React JS 的 this.setState 回调中使用 this.setState?

是否可以在this.setState的回调中调用this.setState?我正在制作一个RoguelikeDungeon并有一个设置,其中在this.setState的回调中使用了一个辅助函数,它再次调用this.setState。我的游戏此时卡住。所以我在React组件中有一个对象,它有一个生成随机二维数组映射的方法:this.Dungeon.Generate();当游戏开始时,我们在componentDidMount()中调用组件中的如下函数:componentDidMount:function(){this.Dungeon.Generate();this.setState({b

JavaScript 本地作用域 : var vs. this

我似乎无法理解JavaScript变量作用域的特定情况。与我发现的其他示例和问题不同,我对嵌套函数的范围界定很感兴趣。我在thisJSFiddle设置了一个示例.相关部分如下:functionMyObject(){varself=this;vara=1;this.b=2;varinnerMethod=function(){//1and2:directreferencelogMessage("a="+a);//a=1//logMessage("b="+b);//Error:bisnotdefined//3and4:usingthislogMessage("this.a="+this.a)

Javascript:Promises + this

这个问题在这里已经有了答案:Howdoesthe"this"keywordwork,andwhenshoulditbeused?(22个答案)关闭6年前。考虑以下代码:foo:function(){varself=this;varp1=p2=someFunctionThatReturnsAPromise();Promise.all([p1,p2]).then(self.bar);}bar:function(promises){varself=this;console.log(self);}输出:undefined但如果我改为执行以下操作:foo:function(){varself=t

javascript - 箭头函数的 this 值

这个问题在这里已经有了答案:MethodsinES6objects:usingarrowfunctions(6个答案)Howdoesthe"this"keywordinJavascriptactwithinanobjectliteral?[duplicate](4个答案)关闭5年前。我正在尝试理解ECMAScript6中的箭头函数。这是我在阅读时遇到的定义:Arrowfunctionshaveimplicitthisbinding,whichmeansthatthevalueofthethisvalueinsideofanarrowfunctionisawaysthesameasthe

javascript - JavaScript WebSocket.send 方法会阻塞吗?

如果我通过JavaScriptWebSocket的send方法发送一个大的Blob或ArrayBuffer。..send方法调用会阻塞直到发送数据,还是复制数据以异步发送以便调用可以立即返回?一个相关的(未回答的)问题是,从我的解释来看,一系列快速发送是否会导致onmessage事件延迟,正如有人描述的那样发生在MobileSafari中:ApparentblockingbehaviourinJavaScriptwebsocketonmobileSafari 最佳答案 根据bufferedAmount属性的描述,我推导出send必须

javascript - ES6 箭头函数正在改变 Meteor.publish 中 this 的范围

这个问题在这里已经有了答案:Whatdoes"this"refertoinarrowfunctionsinES6?(10个答案)关闭7年前。所以我开始在Meteor中使用ES6,但显然如果你尝试使用带有箭头函数的Meteor.publish语法,this.userId是未定义的,而如果您将它与常规function(){}一起使用,this.userId可以完美运行,我假设是一种分配不同这,到userId但这只是一个猜测,有谁知道到底发生了什么?Meteor.startup(function(){Meteor.publish("Activities",function(){//withf

javascript - 在 javascript 的父闭包中引用 "this"

我想在Javascript中这样做:functionZ(f){f();}functionA(){this.b=function(){Z(function(){this.c()});}this.c=function(){alert('helloworld!');}}varfoo=newA();foo.b();可以这样实现:functionZ(f){f();}functionA(){varself=this;this.b=function(){Z(function(){self.c()});}this.c=function(){alert('helloworld!');}}varfoo=n

javascript - 为什么 `this===window` 给我假的?

我一直在测试以下代码,但Firefox16和Chrome22给出了不同的结果。console.log(this===window);//falseinFirefoxandtrueinChromeconsole.log(this.window===window);//trueinbothFirefoxandChrome(function(){console.log(this===window);//falseinFirefoxandtrueinChromeconsole.log(this.window===window);//trueinbothFirefoxandChrome})();

javascript - XMLHttpRequest Post 上 send() 数据参数的最大长度

对于主要浏览器实现,是否有可在XMLHttpRequest的发送方法中使用的字符串数据的最大长度记录?当数据超过大约3k时,我遇到了JavaScriptXMLHttpRequest发布在FireFox3中失败的问题。我假设Post的行为与传统的FormPost相同。W3C文档提到发送方法的数据参数是一个DOMString,但我不确定主要浏览器是如何实现它的。这是我的JavaScript的简化版本,如果bigText超过大约3k,它会失败,否则它会工作......varxhReq=createXMLHttpRequest();functioncreateXMLHttpRequest(){

javascript - 如何从 jQuery 函数访问外部 this?

出于好奇,有没有办法从paint函数访问this.color?functionFoo(color){this.color=color;this.paint=functionpaint(){$("select").each(function(idx,el){$(el).css("background",color);//OK//$(el).css("background",this.color);//this.colorisundefined})}}newFoo("red").paint();谢谢 最佳答案 varthat=this;