Run this
void setup(){
all = new obXX[0];
}
here in Chrome.
Expected: Error.
Observed: No error. Why?
PS all = new obXX;
gives a ReferenceError as expected.
Run this
void setup(){
all = new obXX[0];
}
here in Chrome.
Expected: Error.
Observed: No error. Why?
PS all = new obXX;
gives a ReferenceError as expected.
My guess – and I defer to Processing.js experts like @GoToLoop on this – is that this is because openprocessing uses Processing.js, and Processing.js is not bothering to enforce correctness in Java syntax when it compiles to JavaScript – instead, it is assuming that you are writing hybrid Java / Javascript, and attempting to interpret it as valid.
http://processingjs.org/articles/jsQuickStart.html#javascriptonlyprocessingcode
So, if you inspect your example using the code helper:
http://processingjs.org/tools/processing-helper.html
…you can see that the compiler has created an array and assigned it to “all”
// this code was autogenerated from PJS
(function($p) {
function setup() {
all = $p.createJavaArray('obXX', [0]);
}
$p.setup = setup;
setup = setup.bind($p);
})
The section “Writing Documents that Combine Processing and JavaScript Code” seems like it might explain what is happening with that output.