Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

How to use constants as Object keys

オープン
#35 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
42/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript
領域
documentation

調査の方向性

参照されている動画セグメント、提供された p5.js の例、および computed property names に関する MDN のリファレンスを確認してください。関連するプロジェクトのガイダンスを更新し、角括弧が定数の数値をオブジェクトのキーとして使用することを説明したうえで、修正後の例が示されている出力と一致することを検証してください。

索引モデルが issue の本文から書いたものです。

説明

At 22:24 in the video Dan tries to use his constants as the keys in the object but it doesn't work for him. This is because he did it wrong.

when he did it you ended up with an object that had the strings "UP", "DOWN", etc as the keys but you wanted it to be the numbers that those constants represented. The way that you do that is to put the variables in square brackets. For example.

const UP = 0;
const DOWN = 1;
const LEFT = 2;
const RIGHT = 3;

const object1 = {
  UP: [],
  DOWN: [],
  LEFT: [],
  RIGHT: []
}
  
const object2 = {
  [UP]: [],
  [DOWN]: [],
  [LEFT]: [],
  [RIGHT]: []
}
  
  console.log(object1) => // {UP: Array(0), DOWN: Array(0), LEFT: Array(0), RIGHT: Array(0)}
  console.log(object2) => // {0: Array(0), 1: Array(0), 2: Array(0), 3: Array(0)}
}

and here's an interactive example https://editor.p5js.org/D_Snyder/sketches/r7rHl0QuA

The term for this is Computed Property Names and more details can be found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#computed_property_names

主要言語
JavaScript
スター
219
フォーク
64
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CodingTrain/Wave-Function-Collapse のほかの issue

CodingTrain/Wave-Function-Collapse の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。