I found a good article on when to use the escape function . The author claims that you should always use escape, except when you are definitely not going to execute the value of the model attribute. For example, if you checked the model attribute is not null :
var model = new Backbone.Model({foo: "Bar"}); if (model.get("foo") != null) { //notice how here we did not use escape $("h1").html(model.escape("foo")); //but here we do }
One related point to be aware of is that if you check the return value from model.escape("foo") , it will always return a string. Therefore, if you expect null , then you may be confused.
console.log(model.get("foo")); // null console.log(model.escape("foo")); // ""
However, as Jeremy Ashkenas points out in a pull report that requests this problem , it makes no sense to check for an attribute after avoiding it.
source share