I have several objects constructed by object literals:
let obj1={
list: [],
a() {},
b() {},
};
let obj2={
list: [],
c() {},
d() {},
};
Now I want to attach a common method to all objects, say
const f=()=>console.log(this.list);
But If I do
obj1.f=f; obj2.f=f;
And try to run it, it will give undefined
.
How to do this so that this
can correspond to the object?