My objects serialize() method is dependent on a call to its clone() method, because of its options to get rid of unwanted data without changing the original instance:

serialize: function(opt_filters) {
    // Cloning even if not filtering.
    var clone = this.clone().applyFilters(opt_filters);
    return clone.doWhatsNeeded();

But the .clone() function uses .serialize() to construct a new instance.

I was wondering if there is a design principle/pattern that provides guidance on which method to resolve the endless loop in (and which, if followed properly, would avoid that situation from coming up again)?

  • 1
    What programming language are you using? – user22815 Sep 25 '15 at 12:21
  • 1
    I don't see a problem. Presumably the clone function will never filter, so you'll never call back into clone. – Ben Aaronson Sep 25 '15 at 12:50
  • @BenAaronson thanks, I summarized incorrectly, fixed. – bebbi Sep 25 '15 at 15:10
  • @Snowman javascript - tried to simplify without having it look too much like python ;) – bebbi Sep 25 '15 at 15:15
  • @bebbi each language has slightly different semantics around cloning and serialization. Specifying the language is important for this type of question, as opposed to a more pure whiteboard/design type of question. – user22815 Sep 25 '15 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.