It usually happens by accident. For example, let's say you have a class Person with two data members named firstName and lastName. We're already in trouble, but let's make it worse: It has a getter named fullName which returns $`{this.firstName} {this.lastName}`.
That getter looks inoffensive and will, depending on your requirements, work just fine. But it has side effects because the string interpolation allocates and could trigger a garbage collection.
Note that if you're using modern JS 'class' blocks a 'get x ()' will be ignored by JSON.stringify, so if you're aiming to reproduce this you have to use old-school Object.defineProperty instead.