Andy_AO User

It "works" for you only because it's compiled into ES5 or otherwise reorganized by the bundler. The code is invalid by itself: class declarations are initialized in the order of their appearance in the source code as it's just a syntactic sugar for prototype assignments so you can use it only after it was declared. Move Foo.classMethod() to the end.


The following code works in its own HTML, but it doesn't seem to work in userscript.


class Foo {
    static classMethod() {
        return 'hello';

I googled for information about using object-oriented syntax in userscript. I didn't get anything. I just read the document and didn't find the answer.

Who knows what's going on ?