-
Notifications
You must be signed in to change notification settings - Fork 147
Same hash after re-assigning the value of a function variable #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi 👋 , by way of introduction, I help maintain
|
Did some more thinking about this problem and ended up making a trip down memory lane to the pre-ES6 days and remembering how prototypal inheritance works in JS 😅 yea this isn't possible...
So this is, practically speaking, impossible. Closures are literally designed so that they're not introspectable. The ES spec does not expose this to the end-user. And back in the ES5 days, closures are how we made "classes" with "private" properties (and ES private fields are a pretty recent feature that came after ES6 too). So this isn't meant to be possible. (... aside from a fun answer about brute forcing) there are some debugging tools and newer features, but not really a solution
Indeed, some of the answers point to using There's one answer about using ES6 Proxies which would qualify as a "newer development", but that would require the user knowingly wrapping things with Proxies, which well, is an unrealistic expectation. compile-time knowledge is more or less required
This is a pretty important caveat I made in my previous comment, compile-time vs. runtime. Some of the answers get complicated enough to mention parsing the JS code returned from While a Babel macro or ESLint rule is technically possible, that's still a workaround, and not applicable in all situations.
Of course, I think it's a pretty big statement in and of itself that the React team, with Facebook/Meta's backing and some compiler/runtime subject matter experts working on advanced features like hooks, scheduling, etc, couldn't solve this problem and had to settle for a dependencies array plus an ESLint rule. I also remembered another similar scenario, that of next stepsSo I think if neither React nor Babel has solved this, it might be a bit presumptuous to think of solving this. Indeed, as I mentioned previously, I think a Babel macro or ESLint rule might be the only real "solution" to this, which are not particularly practical for this use-case. That being said, given that this is like at least the 4th time a similar issue has cropped up in this library, a warning similar to Babel's might be good to add to the docs with regard to any objects with "dynamic" properties like functions. Or perhaps But yea, I think that's about all that can be done about this, and there isn't really a "bugfix" or "feature" that can really be created for this problem. |
There’s a lot of text here, but yeah, ultimately it boils down to:
Given the popularity of this project, and the lack of maintenance resources, my primary concern for this library is keeping compatibility with existing versions, and so I don’t see a reasonable way to take action here. (The real problem is that a lot of people don’t think about what this library inherently cannot do before starting to use it – but that’s not an easy problem to solve.) |
Hi,
object-hash
team!I have the following scenario:
Because of the changes applied to that
function
I would expect a different hash but I'm obtaining the same hash.here's an example that reflects the scenario I just described: https://codesandbox.io/s/object-hash-with-variables-0bskw
Is this correct? Would be reasonable to try to cover this use case?
You can find the full context in this other issue: ezolenko/rollup-plugin-typescript2#228
The text was updated successfully, but these errors were encountered: