K
K
Konstantin2020-02-15 15:14:06
typescript
Konstantin, 2020-02-15 15:14:06

How to make a record shorter?

public pin(object: PinnedObject): void {
    object.pinned = !object.pinned;
    object.date = new Date();
  }


How to write this record shorter and more beautiful?

Maybe so, but how good is it?

function pin(object: PinnedObject): void {
    object = { ...object, pinned: !object.pinned, date: new Date()}
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-02-15
@Junart1

"You can not do it this way. Because this new objectmethod will not go anywhere and will be collected by the GC.
In general, the existing record does not require any changes. Actions are taken in the same way. There is nowhere to improve and there is nothing.
If there were a whole bunch of assignments, one could think of Object.assign, but here it is definitely not worth it and will only worsen readability.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question