Seeking advice on two different approaches to implementing a method with a constant. Unsure about the better option. Can someone provide guidance? Thank you!
Approach 1: Declaring the constant outside of the class, causing it to be invoked only once but requiring the return of a new variable.
const X = {a: 0, b: 1, c: 2}
export class A{
private method a (val: any) {
return {...X, ...val}
}}
Approach 2: Placing the constant within the method, resulting in the invocation of the constant every time the method is called (twice in this scenario) but eliminating the need for creating a new object.
export class A{
private method a (val: any) {
const x = {a: 0, b: 1, c: 2}
return Object.assign(x, val)
}}