Skip to content
loading...

re: Pro Tip: How to find the accidental mutation VIEW POST

FULL DISCUSSION
 

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.

code of conduct - report abuse