-2

I have removed my question text, as it didn't address the real error in my code. The two answers fully explain my error, and why I had made it.

John
  • 605
  • 9
  • 28
  • 1
    Uh, what did you expect? That's just the result that `JSON.stringify` is supposed to give with those arguments. – Bergi Mar 26 '15 at 04:22
  • 1
    No, this has nothing to do with prototype inheritance as in the question that you linked. – Bergi Mar 26 '15 at 04:26
  • 1
    _"Which Workaround to use?"_ Workaround for what? It's not clear what result you're expecting. Could you tell us that? (i.e. Show us the console output you think you're supposed to be seeing). – JLRishe Mar 26 '15 at 04:27
  • @John: But if you specify to only stringify `changedProperties` properties, you won't get `a` properties! Why are you filtering them at all? – Bergi Mar 26 '15 at 04:39
  • @John: Your problems are neither related to the use of the `this` keyword nor to variable scopes, that's why I have removed those tags from the question. – Bergi Mar 26 '15 at 04:41
  • @John: Please explain what you are intending to use `basicObjectElements` for and what you think passing them to `JSON.stringify` does. – Bergi Mar 26 '15 at 04:43

1 Answers1

1

The second argument to JSON.stringify is applied recursively, not just at the top level. You're not seeing the "a" property because your basicObjectElements array doesn't contain "a". You will see it if you do this:

var basicObjectElements = ["changedProperties", "a"];
JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • @John: So what? The replacers (including propertyname-array filters) need to be applied to every visited object, otherwise they'd be useless. If you want per-object distinctive behaviour, use `.toJSON` methods. – Bergi Mar 26 '15 at 05:32