mardi 30 janvier 2018

Javascript access parameter inside custom sort function

I have a custom sort function defined & call it as below;

myArr.sort(this.sortArrayBy, key);

sortArrayBy: function(a, b) {

    let param = this.get('sortKey'); //How do I get this value here ? cannot pass it as param OR even access via 'this'

    if (a.param < b.param)
        return -1;
    if (a.param > b.param)
        return 1;
    return 0;
},

I want to pass an additional param inside that function. How do I get access to that class attribute ?

P.S: This code is inside my Ember controller class




Aucun commentaire:

Enregistrer un commentaire