Why does this work?

node v8.17.0
version: 1.0.0
endpointsharetweet
class Article { constructor(title, date) { this.title = title; this.date = date; } static compare(articleA, articleB) { return articleA.date - articleB.date; } } // usage let articles = [ new Article("Mind", new Date(2016, 1, 1)), new Article("Body", new Date(2016, 0, 1)), new Article("JavaScript", new Date(2016, 11, 1)) ]; articles.sort(Article.compare); console.log( articles[0].title ); // Body
Loading…

no comments

    sign in to comment