πŸ“Š Survey - data type of empty properties

Let’s say that you want to read the author name in document metadata console.log(myDoc.info.author);.

If the value is missing/empty what would you expect to be returned? Also what would you use to set an empty value back? e.g. myDoc.info.author = myVariable;

  • null value
  • empty text string ""
  • something else - please write in the comment

0 voters

It depends on what you mean by missing/empty
If value was never set, then null. If it was set at some point, but user deleted it, it should be empty string "". But programmatically on plugin side I would probably want to have info setters and getters instead of properties.

  • info.setAuthor(author: string)
  • info.clearAuthor() (or remove/unset) would set info.author = null

I mean if user submits an empty string from input, then it should be saved as empty string. If you want to allow user explicitly completely unset some info, there should be a separate button for that or at least a checkbox, which would disable the input

I really don’t like public properties
My personal opinion

1 Like

How would you read it then? info.getAuthor() ?

Yes, exactly like that :slight_smile:

Could you describe what you don’t like about public properties?

What happens if I try this?

info.author = {name: 'John', lastName: 'Doe'}

Or

info.author = someCallback

What will prevent me from assigning anything I want? :thinking:

Yes. Because in fact there will be setters/getters (instead plain properties) under the hood. And in this place we can validate argument type and throw error to stop you before it is set :smiley:

Also if info will be sealed then it will prevent you to accidentally add new properties and remove existing ones. Object.seal() - JavaScript | MDN

2 Likes

Didn’t know about seal() :+1: Then maybe it’s fine to have it like this. So I vote for null :smiley: But still would like differentiation if author was never set or user deleted it :thinking:

1 Like