Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

mutating the [[Prototype]] of an object will cause your code to run very slowly #51

Closed cramhead closed 10 years ago

cramhead commented 10 years ago

Question: On Firefox, have the following warning.

TypeError: 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 debugger points to CollectionHooks.reassignPrototype. I takes two arguments, i.e. instance and constr, but when I search the code I only find one reference to the function in user-compat.js. It's called with only one parameter, i.e. CollectionHooks.reassignPrototype(Meteor.users); I'm assuming it gets called or Firefox would not be complaining.

I guess the questions are:

  1. Does the function act as expected, considering the missing prototype?
  2. Could Firefox be outputing the message even thought it's not called, i.e. a parsing check?
  3. Is there an different approach that would not have a warning and performance penalty?
mizzao commented 10 years ago

This is being done in https://github.com/matb33/meteor-collection-hooks/blob/master/collection-hooks.js#L169.

I recall that @matb33 did this because of #34, and something else I don't really remember. Was it because of interoperability with collection2?

matb33 commented 10 years ago

Actually it was for meteor-collection-helpers, but it could apply to other packages in the future. We discuss it here: https://github.com/dburles/meteor-collection-helpers/issues/2#issuecomment-37421230

This is related to how the accounts package instantiates Meteor.users before our package has a chance to hook itself up.