javascript question regarding 'this' and mlang.DESC

12 views
Skip to first unread message

Joel Hughes

unread,
Mar 6, 2018, 12:34:43 AM3/6/18
to foam-framework-discuss
When I use DESC with OrderBy, the 'this' in mlang.DESC is 'window'.
The OrderBy without DESC is working just fine.
The DAO in question has been in use for some time, but it's the first time I've called it with an OrderBy with Desc.

Thanks for any ideas.
Joel

dao = dao.orderBy(
    //this.Workorder.START_DATE
    this.DESC(this.Workorder.START_DATE)
    //this.Desc.create({arg1: this.Workorder.START_DATE},this)
);

A DAO {
  select_(x, sink, skip, limit, order, predicate) {
    ...
    var arr = [];
    ...
    var unique = this.sortUnique(arr, order, predicate);

  }

  function sortUnique(arr, order, predicate) {
    var unique = [];
    ...
    return unique.sort(order.compare);  invokes Desc.compare (below)
  }
}

mlang.order.Desc
  methods: [
    function compare(o1, o2) {
      return -1 * this.arg1.compare(o1, o2);
    },
'this' is window 

Kevin Greer

unread,
Mar 6, 2018, 7:45:36 AM3/6/18
to Joel Hughes, foam-framework-discuss
Who is calling sortUnique()? that line should be:

return unique.sort(order.compare.bind(order));



--
You received this message because you are subscribed to the Google Groups "foam-framework-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to foam-framework-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages