Class Musescore error

• Mar 10, 2023 - 18:42

Hi guys Iam trying to ran this code
class Note {
constructor(randomOrder, lenghtOne, lenghtTwo) {
this.randomOrder = randomOrder;
this.lenghtOne = lenghtOne;
this.lenghtTwo = lenghtTwo;

}
}

but it gives me following errors

Creating component failed
line 3: Unexpected token reserved word'
line 4: Expected token
:'
line 4: Expected a qualified name id

Do you know what is wrong ?


Comments

I never used that syntax for creating classes in MuseScore/Javascript.
This is the syntax I'm using is the following one and it is working fine:

function tpcClass(tpc, name, accidental) {
    this.tpc = tpc;
    this.name = name;

    this.raw = name.substring(0, 1);

    this.pitch = tpcToPitch(tpc);

    if (accidental !== undefined) {
        this.accidental = accidental;
    } else {

        var a = name.substring(1, name.len);
        switch (a) {
        case '♯♯':
            this.accidental = 'SHARP2';
            break;
        case '♯':
            this.accidental = 'SHARP';
            break;
        case '♭♭':
            this.accidental = 'FLAT2';
            break;
        case '♭':
            this.accidental = 'FLAT';
            break;
        default:
            this.accidental = 'NONE';
        }
    }

    this.toString = function () {
        return this.raw + " " + this.accidental;
    };

    Object.freeze(this);

}

And you can instantiate new objects the same way:

var tpc=new tpcClass(0, 'C♭♭');

Do you still have an unanswered question? Please log in first to post your question.