stuyam / pressure

:point_down::boom: JavaScript library for handling Force Touch, 3D Touch, and Pointer Pressure.
https://pressurejs.com
MIT License
2.92k stars 97 forks source link

Firefox console warning: _mutating the [[Prototype]] of an object will cause your code to run very slowly #33

Closed jalbam closed 8 years ago

jalbam commented 8 years ago

Hello,

Thanks for this script. It is great!

Using Pressure.js with Firefox 47.0.1 64 bit on Windows 10, you can see this warning in the console:

mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create

The function that is causing problems is the one called "_inherits". I guess it is because it is trying to do this:

subClass.proto = superClass;

Could that warning be fixed, please? Despite that fact that it is not so serious and it should still work even with the warning, it does not look nice.

What I am doing now to prevent this warning is to detect whether "webkitmouseforcewillbegin" event is supported by the browser and if so, I lazy load the script.

Cheers, Joan

jalbam commented 8 years ago

Sorry. I just noticed that we cannot relay on detecting "webkitmouseforcewillbegin" support because some browsers/devices with force touch or 3D touch will give false positives and false negatives. So I decided to load always the Pressure.js library.

stuyam commented 8 years ago

@jalbam sorry to hear that is happening. It sounds like it has to do with how babel is creating hierarchy and using proto instead of using normal prototypical inheritance the full way. I am going to look into if I can get babel to compile it differently.

Thanks for bringing this to my attention I will look into it now 👍

jalbam commented 8 years ago

You are welcome. Thanks to you for the great library.

stuyam commented 8 years ago

If anyone knows anything about how babel compiles with the __proto_ inheritance and if that can be changed to extend the prototype let me know. Would love to know if anyone has encountered this elsewhere and how it can be fixed.

stuyam commented 8 years ago

This doesn't seem to be throwing an error in the latest versions of Firefox 49 and since this is an issue with babel and the way they set legacy support for inheritance, it is not a big issues for me. Anyone that has this issue in the future feel free to bring in back up, just doesn't seem to be a priority.