Answer the question
In order to leave comments, you need to log in
How to make a record shorter?
public pin(object: PinnedObject): void {
object.pinned = !object.pinned;
object.date = new Date();
}
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
"You can not do it this way. Because this new object
method 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 questionAsk a Question
731 491 924 answers to any question