Removing jQuery event properties

JavaScript performance comparison

Revision 2 of this test case created by Martin Borthiry


event.layerX & event.layerY will be removed from WebKit soon. Every jQuery-bound event handler now logs this warning:

event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.


See jQuery bug #10531.

It’s possible to prevent jQuery from copying these properties over to its event objects, but what is the fastest way of doing this?

These snippets don’t do exactly the same, but they all have a similar effect: the layerX and layerY properties aren’t copied to jQuery event objects anymore.

Preparation code

<script src="">
  var props = $.event.props;

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
join, replace, and split
// reset
$.event.props = window.props;
// remove layerX and layerY
$.event.props = $.event.props.join('|').replace('layerX|layerY|', '').split('|');
Using $.map
// reset
$.event.props = window.props;
// remove layerX and layerY
$.event.props = $.map($.event.props, function(prop) {
  return /^layer/.test(prop) ? null : prop;
while loop + delete
// reset
$.event.props = window.props;
// remove layerX and layerY
var props = $.event.props,
    length = props.length;
while (length--) {
  /^layer/.test(props[length]) && delete props[length];
while loop + new array
// reset
$.event.props = window.props;
// remove layerX and layerY
var all = $.event.props,
    len = all.length,
    res = [];
while (len--) {
  var el = all[len];
  if (el != 'layerX' && el != 'layerY') res.push(el);
$.event.props = res;

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

1 comment

dmethvin commented :

What difference does it make which is faster? This should only be run once on startup. I'd do the string join/replace/split method for simplicity.

Comment form temporarily disabled.

Add a comment