Skip to content

escape method cache issue #8

Closed
mimopo opened this Issue Nov 2, 2012 · 1 comment

2 participants

@mimopo
mimopo commented Nov 2, 2012

If you try to use "escape" method with mutators it will be cached, this is a problem since mutators are dynamic.

Example:

window.Example = Backbone.Model.extend({
    defaults:{
        a: 1,
        b: 1
    },
    mutators:{
        c: function(){
            return this.a + this.b;
        }
    }
});
var E = new Example();
alert(E.escape("c")); // displays 2
E.set("a", 2);
alert(E.escape("c")); // displays 2, must be 3

Possible fix:

// override get functionality to get HTML-escaped the mutator props
    Mutator.prototype.escape = function (attr){
        var val = this.get(attr);
        return _.escape(val == null ? '' : '' + val);
    };
@asciidisco asciidisco was assigned Dec 13, 2012
@asciidisco
Owner

Implemented & tested, will be in the next release.

@asciidisco asciidisco closed this Apr 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.