Chartjs-Use Chart.js draw method as Typescript arrow function

0👍

You can use ES6 shorter syntax for method definitions on objects initializers.

 Chart.controllers.line = Chart.controllers.line.extend({
        draw () {
          const ctx = this.chart.chart.ctx;

If you use lower version of js, you can:

 Chart.controllers.line = Chart.controllers.line.extend({
        draw: function draw () {
          const ctx = this.chart.chart.ctx;

You can check how ES6 syntax is converted to older js with babel: interactive example

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions

0👍

I don’t think you do need to convert it to an arrow function. Try this style of object literal method declaration:

Chart.controllers.line = Chart.controllers.line.extend({
  draw() {
    //...
  }
})

See examples of good usage of the func-names rule here.

Leave a comment