Refactoring this javascript code
<p>I have this javascript code and im not happy the way it is written..</p>

<pre><code>function notesViewModel() {
    _this.colName = "CreatedDate";
    _this.sortOrder = "desc";
    _this.notes = ko.observableArray();

   _this.SortItems = function (colname) {
        var newNotes = _this.notes();
        if (_this.sortOrder === "desc") {
            this.notes(newNotes.sort(notesViewModel._getSortFunction = function (a, b) {
                return a[colname] &lt; b[colname] ? -1 : 1;
            }));
            switchSortOrder();
        } else {
            this.notes(newNotes.sort(notesViewModel._getSortFunction = function (a, b) {
                return a[colname] &gt; b[colname] ? -1 : 1;
            }));
            switchSortOrder();
        }
    };
    function switchSortOrder() {
        if (_this.sortOrder === "asc") {
            _this.sortOrder = "desc";
        } else {
            _this.sortOrder = "asc";
        }
    }
 ko.applyBindings(_this, $("body").get(0));
return _this;
}
</code></pre>

<p>how can I pass the sort order into anonymous function and call it to return the required bubble sort? </p>
