Skip to content

ReferenceError occurs when referencing a class before it's defined #33

Open
@RobbieGM

Description

@RobbieGM

Hi Leonardo,
You mentioned in this stackoverflow discussion that you attempt prevent causing ReferenceErrors by using the typeof operator, but I showed how they can occur anyway and you said "let me check because this seems like a bug". After much head-scratching, I figured out why this is the case.

let x = 8;
console.log(typeof x); // "number"
console.log(typeof y); // "undefined"
console.log(typeof z); // ReferenceError: cannot access variable z before initialization
let z = 9;

If you don't define something at all, the typeof operator will give you "undefined". But in my case the class was defined too late, and that for some reason causes a ReferenceError. I don't know what to use instead of typeof (maybe a try-catch?) but I just wanted to let you know about this weird language kludge and how you could improve your plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions