小编use*_*079的帖子

Javascript const在chrome dev控制台中出现未定义且未定义

我有一个newProducts返回的const ,undefined但是说它在chrome dev控制台中没有未定义: 在此输入图像描述

它表示它在控制台中以黄色突出显示的文本定义,并且在鼠标悬停在其上时未定义.它不应该是未定义的.我已逐步完成代码,returns内部map返回值.这是为什么const来了undefined,也没有undefined

searchResults.reducer.js

// @flow
import initialState from '../../config/config'
import {
  FETCH_PRODUCTS_REJECTED,
  UPDATE_SEARCH_RESULTS
} from '../search-page/searchPage.action'
import { SET_SELECTED_SHOP } from '../search-results/searchResults.action'

const searchResults = (
  initialResultsState: [] = initialState.get('searchResults'),
  action: Object): string => {
  switch (action.type) {
    case UPDATE_SEARCH_RESULTS: {
      const newProducts = action.payload.products.map(product => {
        return {
          shop: {
            id: product.shop[0].f1,
            name: product.shop[0].f2,
            coordinate: {
              latitude: product.shop[0].f4,
              longitude: product.shop[0].f3
            },
            selected: false …
Run Code Online (Sandbox Code Playgroud)

javascript react-native redux react-redux

2
推荐指数
1
解决办法
1806
查看次数

调用函数时变量不变

有人看到我的代码中的一个错误,阻止变量"player1Bananas"改变?功能中的其他所有功能都可以正常工作

 //update playerStats arguments:
    //banana is a banana object
    //x and y are the banana's position
    //players bananas is player1Bananas or player2Bananas,
    //ballPosition is "left" or "right"
    updatePlayerStats: function(banana, x, y, playersBananas, ballPosition) {   
        playersBananas += 1;
        gameController.bananasTaken += 1;
        banana.x = x;
        banana.y = y;
        gameController.player1Score = 0;
        gameController.player2Score = 0;
        gameController.setUpPaddles();
        gameController.setUpBall(ballPosition);
    },
    gameController.updatePlayerStats( gameController.Banana1, 20, gameController.canvas.height - 20 - gameController.Banana1.height,
 gameController.player1Bananas, "left");
Run Code Online (Sandbox Code Playgroud)

谢谢!

javascript variables

0
推荐指数
1
解决办法
61
查看次数

如何使这个方法可重用?

我已将此方法复制粘贴到两个类中.我宁愿在第一堂课中重复使用它.这是在Windows窗体应用程序中.

public void defineMapArea()
{
    PictureBox pictureBox1 = new PictureBox();

    // Dock the PictureBox to the form and set its background to white.
    pictureBox1.Dock = DockStyle.Fill;
    pictureBox1.BackColor = Color.White;

    // Connect the Paint event of the PictureBox to the event handler method.
    pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);

    // Add the PictureBox control to the Form. 
    this.Controls.Add(pictureBox1);
}
Run Code Online (Sandbox Code Playgroud)

在方法中从一个类到另一个类需要改变的唯一事情是"this"关键字引用类,因为悬停在"this"上确认.我想也许"this"只适用于调用方法的类,但我认为它仍然引用了定义方法的类.简单地将类作为参数传递会很棒,但我在思考这不起作用,因为我尝试过.

任何帮助赞赏.谢谢!

c# reusability

0
推荐指数
1
解决办法
1435
查看次数

C# - 调用绘制事件处理程序

我想在单击按钮时调用我的绘画事件。我有这个:

private void btnDrawMap_Click(object sender, EventArgs e)
        {
            rows = Convert.ToInt32(this.numRows);
            cols = Convert.ToInt32(this.numCols);


            defineCellWallsList();
            defineCellPositionsList();
            pictureBox1_Paint_1;
        }
Run Code Online (Sandbox Code Playgroud)

我认为你不能这样称呼它。所做的一切pictureBox1_Paint_1就是:

private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
        {
            myGameForm.drawMap(e, mapCellWallList, mapCellPositionList);
        }
Run Code Online (Sandbox Code Playgroud)

所以如果我可以打电话myGameForm.drawMap代替,那就太好了。这是:

public void drawMap(PaintEventArgs e, List<List<int>> walls, List<List<int>> positions)
        {
            // Create a local version of the graphics object for the PictureBox.
            Graphics g = e.Graphics;

            // Loop through mapCellArray.
            for (int i = 0; i < walls.Count; i++)
            {
                int[] mapData = getMapData(i, walls, positions); …
Run Code Online (Sandbox Code Playgroud)

c# event-handling

0
推荐指数
1
解决办法
5198
查看次数