javascript forEach范围(javascript forEach scope)
我有以下代码
var tempGameState = JSON.parse(JSON.stringify(this.gameState)) tempGameState.forEach(function(row.bind(this), rowNum){ ... }));
当我在forEach循环之前放置我的console.log时:
var tempGameState = JSON.parse(JSON.stringify(this.gameState)) console.log(this.gameState) tempGameState.forEach(function(row.bind(this), rowNum){ ... }));
我把我的游戏状态作为输出
但当我把它放在forEach循环中时,如下所示:
var tempGameState = JSON.parse(JSON.stringify(this.gameState)) tempGameState.forEach(function(row.bind(this), rowNum){ console.log(this.gameState) ... }));
我得到了
undefined
。我知道这(通常)与范围有关,但是javascript文档没有说明正在创建的新范围或如何处理它。
I have the following code
var tempGameState = JSON.parse(JSON.stringify(this.gameState)) tempGameState.forEach(function(row.bind(this), rowNum){ ... }));
when I put my console.log before the forEach loop like so:
var tempGameState = JSON.parse(JSON.stringify(this.gameState)) console.log(this.gameState) tempGameState.forEach(function(row.bind(this), rowNum){ ... }));
I get my game state as the output
but when I put it inside the forEach loop like so:
var tempGameState = JSON.parse(JSON.stringify(this.gameState)) tempGameState.forEach(function(row.bind(this), rowNum){ console.log(this.gameState) ... }));
I get
undefined
.I know this (ususally) has to do with scoping, but the javascript docs don't say anything about a new scope being created or how to handle this.
原文:
最满意答案
检查以确保您没有冲突的路线。 当URI匹配两个或更多控制器操作,因此Web API无法选择一个时,您将收到500错误。
I figured out what was going on. There were actual errors occurring (mostly SQL related), but the way that we had configured the functions and error logging in those functions, the actual errors were being swallowed up and lost, overriding the error logging behavior of Raygun. I went through and ripped out the Try/Catch blocks we were using for error trapping and logging and the real errors finally emerged into the Raygun dashboard.
相关问答
更多-
常州文联艺术培训中心民乐乐理考试怎么收费的[2023-10-20]
500 -
河北师大对口招生电脑分数线是多少?[2022-08-17]
500 -
滁州腾达计算机培训学校计算机培训班多少钱?[2023-11-08]
500 -
河南文科生考南阳师院电脑专科系要多少分?[2022-05-30]
500 -
HTTP 500来自其他东西。 我准确地添加了您在新的空WebSite中所做的操作,结果与预期一致。 要测试的URL: http : //jsonp.azurewebsites.net/demo.json 这是来自请求的小提琴跟踪: GET http://jsonp.azurewebsites.net/demo.json HTTP/1.1 User-Agent: Fiddler Host: jsonp.azurewebsites.net 响应也如预期: HTTP/1.1 200 OK Content-Le ...
-
原来这是我如何实例化uwsgi的问题。 我从头开始删除了所有内容,并使用uwsgi浏览了烧瓶安装说明,并且能够使一切工作正常。 Turns out it was an issue with how I was instantiating uwsgi. I removed everything from scratch and walked through the flask installation instructions with uwsgi and was able to get everything ...
-
您收到的消息是您不能使用: var sql = require("mssql"); 但是const sql = require("mssql"); 这是因为你使用'strict mode'; 。 在文件的顶部,在javascript中,你使用'use strict'; 要了解有关''use strict'的更多信息,请参阅: http : //www.w3schools.com/js/js_strict.asp The message you are receiving is that you cannot ...
-
我从以下地址找到了我的问题的答案: Web Api + HttpClient:异步模块或处理程序在异步操作仍未完成时完成 我将定义更改为我的WebAPI控制器: public **async Task
** Post([FromBody]GPSDataVM data) { if (KeyRepository.IsValid(data.Key)) { // Creates a document in Documen ... -
Azure上的WebApi应用程序为某些端点返回500个错误(WebApi application on Azure returning 500 errors for some endpoints)[2023-06-26]
检查以确保您没有冲突的路线。 当URI匹配两个或更多控制器操作,因此Web API无法选择一个时,您将收到500错误。 I figured out what was going on. There were actual errors occurring (mostly SQL related), but the way that we had configured the functions and error logging in those functions, the actual errors w ... -
在你的Global.asax.cs中 public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { // Try adding the following lines: var configuration = GlobalConfiguration.Configuration; var formatters = ...