# javascript class definition in Observable

**URL:** <https://talk.observablehq.com/t/javascript-class-definition-in-observable/5784>\
**Category:** Help\
**Created:** [November 7, 2021, 11:33pm UTC](https://talk.observablehq.com/t/javascript-class-definition-in-observable/5784 "2021-11-07T23:33:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igor-A1](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/igor-a1/32/5755_2.png) [@Igor-A1](https://talk.observablehq.com/u/Igor-A1)\
**Post date:** [November 7, 2021, 11:33pm UTC](https://talk.observablehq.com/t/javascript-class-definition-in-observable/5784/1 "2021-11-07T23:33:29Z")

</div>

can’t find any difference in standard class definition in Observable ☹

```auto
class User {
    #nameValue

    constructor(name) {
        this.name = name
    }

    get name() {
        return this.#nameValue
    }

    set name(name) {
        if (name === '') {
            throw new Error('Empty user name')
        }
        this.#nameValue = name
    }
}

const user = new User('username1')

```

static and private fields and method not supported.  
what other restrictions are there, help please

---

<div class="post-metadata">

**Author:** ![tophtucker](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tophtucker/32/4781_2.png) [@tophtucker](https://talk.observablehq.com/u/tophtucker)\
**Post date:** [November 8, 2021, 12:33am UTC](https://talk.observablehq.com/t/javascript-class-definition-in-observable/5784/2 "2021-11-08T00:33:27Z")

</div>

Yes, Observable does not support class fields yet. I’m sorry, I’ve run into this limitation too, it’s annoying and it’s been true for a while. I’ve just reopened [this old issue for it](https://github.com/observablehq/parser/issues/64).

I don’t know if we currently have any comprehensive documentation of what’s unsupported but I can check. I just put a [notebook of test cases for public and private class field syntaxes](https://observablehq.com/d/9d5fece07851737e).

Of the syntax examples from MDN, the only one that currently works on Observable is:

```auto
class ClassWithPublicInstanceMethod {
  publicMethod() {
    return 'hello world'
  }
}

```

---

<div class="post-metadata">

**Author:** ![Igor-A1](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/igor-a1/32/5755_2.png) [@Igor-A1](https://talk.observablehq.com/u/Igor-A1)\
**Post date:** [November 8, 2021, 2:05am UTC](https://talk.observablehq.com/t/javascript-class-definition-in-observable/5784/3 "2021-11-08T02:05:53Z")

</div>

i think that Observable using classes as _syntax sugar_ on **prototype** entity. not new features of modern _js_ standard.
