Edit in JSFiddle

$(function() {    
    Object.defineProperty($("#foo").get(0),"value", {        
        set: function(val) { debugger; }
    });
    $("#foo").change(function() {
      $(this).val($(this).val() + " - after change");
    });
    
    // ... other code in the system ...
    
    $("#foo").change(function() {
      // Buggy code
        $(this).val("");
    });
});
Write something in the input field, then click outside of it. The expected result is the string " - after change" is added to the input value, but the buggy code removes the entire value all together.
<br/>
<input type="text" id="foo">