DEV Community

Discussion on: Pro Tip: How to find the accidental mutation

Collapse
 
aghost7 profile image
Jonathan Boudreau • Edited

You can also use setters to figure out where a mutation on a specific property is coming from:

var person = { name: 'foobar' };

var name = person.name;
Object.defineProperty(person, 'name', {
  set(value) {
    console.trace('Changing to value: %s', value);
    name = value;
  }
  get() {
    return name;
  }
});

This way you don't need to put use strict everywhere to find the culprit.