sveltejs / v2.svelte.dev

The Svelte v2 website
https://v2.svelte.dev
MIT License
210 stars 79 forks source link

POJO #30

Open nsaunders opened 7 years ago

nsaunders commented 7 years ago

In the component.set API documentation, what exactly is meant by the term "POJO"? Is it proper for a data property, for example, to reference a function?

I just noticed b3a79f1710052c84597bfbe93db79142fc595bb3, and it's a great start, but still could be further explained IMO.

Ryuno-Ki commented 7 years ago

POJO stands for Plain Old JavaScript Object.

nsaunders commented 7 years ago

I am aware of the acronym, thanks. I'm looking for a more precise definition.

Rich-Harris commented 7 years ago

I think it's commonly used to distinguish between objects that are created via object literals, and objects created via new expressions or Object.create — i.e. no prototype. Also, if an object has getters and setters I'd no longer consider it a POJO.

The reason for the prohibition is if you had something like this...

<script>
  export default {
    data () {
      return new Foo();
    }
  };
</script>

...then you might get unexpected behaviour.

Is it proper for a data property, for example, to reference a function?

It's fine to do that, though referenced functions should be pure. Alternatively you can put those functions on helpers.

Not sure how to communicate all that succinctly in the docs!