Does anyone know how to convert the following JS c...
# javascript
s
Does anyone know how to convert the following JS code to KotlinJS:
Copy code
const plugin = {
  beforeInit(chart) {
    // Get a reference to the original fit function
    const originalFit = chart.legend.fit;

    // Override the fit function
    chart.legend.fit = function fit() {
      // Call the original function and bind scope in order to use `this` correctly inside it
      originalFit.bind(chart.legend)();
      // Change the height as suggested in other answers
      this.height += 15;
    }
  }
}
What I tried so far:
Copy code
val plugin = obj {
        beforeInit = { chart : dynamic ->
            val fitValue = chart.legend.fit
            chart.legend.fit = {
                fitValue.bind(chart.legend)()
                this.height += 50
            }
        }
    }
Nvm figured it out, didnt understand that the bind one would change the scope that
this
refers to, the fix is:
Copy code
chart.legend.fit = {
                fitValue.bind(chart.legend)()
                chart.legend.height += 50
            }
t
Is it known JS library, for which you write plugin?