私はこのエラーメッセージ "TypeError:aは未定義です"としばらくの間、私は最終的に私のプロジェクトのコードのいくつかの行に絞り込んだ。変数私はコンソールに来ていませんでしたp5
new p5();
var particle = function(X, Y, C, Kind, Fun) {
this.pos = createVector(X, Y);
this.vel = createVector(0, 0);
this.accel = createVector(0, 0);
this.col = C;
this.isDead = false;
this.kind = Kind;
this.affect = Fun;
};
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
};
var particles = new Array(new particle(1, 1, color(1, 1, 1), function() {
cosole.log("your mamma");
}));
function draw() {
};
これをブラウザで実行すると、上記のエラーメッセージが表示されます。あなたのHTMLがどのように見えるか疑問に思った場合、ここにあります:
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script src="p5.min.js"></script>
<script src="p5_test.js"></script>
</head>
<style>
body {margin: none; padding: none;}
</style>
<body></body>
</html>
何か提案がありますか?
もう一つは、グローバルなスコープでp5関数にアクセスすることができないことです。これは、 'draw'や' setup'のようなp5構造体の中にある必要があります。この場合、 'draw'や' setup'の外で 'color(1、1、1)'を使うことはできません。 –
@ MasterYushiスケッチの上部に 'new p5()'があります。これにより 'setup()'が呼び出される前にP5関数を呼び出すことができます。 [wiki](https://github.com/processing/p5.js/wiki/Frequently-Asked-Questions#why-cant-i-assign-variables-using-p5-functions-and-variables-before-セットアップ)を参照してください。 –
@KevinWorkmanはい、ありがとう、このスニペットの問題、* Uncaught TypeError:未定義*の '_colorMode'プロパティを読み取ることができません*は、グローバルスコープで 'color()'が呼び出されたためです。この問題を参照してください。(https://github.com/processing/p5.js/issues/1293) –