Making a Class; web editor vs local

#1

As an exercise in making classes in p5.js, I used a piece of code from Dan Shiffman (2D Ray Casting …).
Something strange happens : when I use the code ->

class Boundary{
   constructor(x1, y1, x2, y2) {
   this.a =createVector(x1,y1);
   this.b =createVector(x2,y2);
   }

   show() {
      stroke(255);
      line(this.a.x, this.a.y, this.b.x, this.b.y);
   }
}

it generates an error : Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
But only when executed locally.
When used in “web editor” it runs fine !
To make it run local I have to declare it as “function” and do the declaration accordingly.

I have searched trough the forum but dit not find any working solution … :frowning:
I also downloaded latest version of P5.js with no result…

Thanks for any help !
Rolembeek

#2

You’re probably using some very old browser. Perhaps as old as 4 years or more! :older_man:

#3

Thnx for your tip.
I am currently using Chrome but wil test it imediately in “Microsoft Edge”. (more recent I hope!)
I’ll post the result.

Cheers,
Rolembeek

#4

I only realize that in fact it IS working in my browser and NOT in local. Does then the browser still have effect on local behaviour ? I checked my Chrome version anuway and it responds that it is uptodate …

#5

What do you exactly mean by local?
RU trying to use the “file:://” scheme on a Chrome-based browser by any chance?


#6

Apparently I didn’t make myself very clear in my question …
I start all over again :wink:

So, I try to write some code with a"Class". (Iused several times in “Processing P3”).
I took an example from Dan Shiffman (2D Ray Casting …).

When I run this code in the “Web editor”, it runs fine.

Now, when running “localy” by executing “P5.exe” from my HDD (see below)
P5js_01

Now I get an error … :frowning:

I hope this makes my problem more clear …

Roland

1 Like
#7
1 Like