pixelkind / p5canvas

An interactive preview for writing p5js code in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=garrit.p5canvas
Other
39 stars 4 forks source link

Enabling es6 version #5

Closed pixelkind closed 5 years ago

pixelkind commented 6 years ago

Enable using let in p5canvas.

Source: Tweet

FrancoisSchnell commented 6 years ago

Would like that :) "live p5" extension works but is not as good for me as p5canvas when making changes without saving file.

pixelkind commented 6 years ago

@metadirective One workaround is to enter

/* jslint esversion: 6 */

at the beginning of the file. But it works not with classes. But that's a problem, that probably can't be solved.

osteele commented 5 years ago

In version 1.2.0 of this extension, at least, jslint (and also jshint) do indeed enable ES6 classes. For example, the following sketch draws the expected rectangle.

/* jslint esversion: 6 */

class Rectangle {
    constructor(x, y, width, height) {
        this.x = x;
        this.y = y;
        this.height = height;
        this.width = width;
    }

    draw() {
        rect(this.x, this.y, this.width, this.height);
    }
}

const r = new Rectangle(10, 20, 50, 100);

function setup() {
    noLoop();
}

function draw() {
    background(255);
    fill(0);
    r.draw();
}