I have this javascript code and im not happy the way it is written..
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] < b[colname] ? -1 : 1;
}));
switchSortOrder();
} else {
this.notes(newNotes.sort(notesViewModel._getSortFunction = function (a, b) {
return a[colname] > 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;
}
how can I pass the sort order into anonymous function and call it to return the required bubble sort?
_this
? It's notthis
... – Izkata Apr 28 at 23:37