Search code examples
mithril.jshyperscript

MithrilJS Hyperscript


m("div", {
  onclick: function(e) {
    console.log(e); 
  }, 
}, "Test")

Hello, i would like to know if having an event handler such as the one above creates a new function on Mithril redraw? I want to avoid performance issues.


Solution

  • It will be recreated on each redraw. The perf impact is generally negligible.

    https://jsperf.com/create-function-vs-reference isn't an exact test, but hopefully provides a rough idea of the difference.

    Always profile though! If the function creation is your bottleneck abstracting it out would be an easy fix.