Open patrick-steele-idem opened 10 years ago
Yep, and I think it's definitely the responsibility of this true library to ensure that it handles every single edge case and odd usage/impact from other third parties...
Yes, exactly! What we need is a way to make true
immutable. Since JavaScript doesn't support such a thing, I came up with the following solution:
setInterval(function() {
if (require('true')() !== true) {
// Fix it!
require.cache[require.resolve('true')].exports = function() {
return true;
};
}
}, 10);
This guarantees that true
will always be returned even if some code tries to redefine it. I would be happy to submit a pull request.
This is brilliant, although I wonder if perhaps the correct place to fix this problem is at the language-level. Perhaps you should submit something like this solution directly to TC39: http://www.ecma-international.org/memento/TC39.htm They have a long history of being incredibly receptive to outside feedback.
Good idea. I will also include a recommendation to fix truthiness in JavaScript. I can't begin to tell you how many times I have been bitten by the following problem with JavaScript:
assert.equal(true, 'true'); // Error!
Clearly they are the same... It's issues like this that almost make we want to switch back to Bash for all of my programming needs.
Object.defineProperty(require.cache, require.resolve('true'), {
writable: false,
configurable: false,
enumerable: true,
value: module.exports
})
This could be really useful for ensuring the integrity of this module. A PR would be helpful to solicit comments, to make sure we get adequate feedback about this potential approach.
Is this serious or just joke?
What could possibly be funny about tiny modules? The good thing about tiny modules is that they're composable!
I think this function should be available in v8
I'm so grateful it's 2022 and all of the npm issues which were so problematic in 2014 have been solved forever. Truly it's a great time to be alive.
Hey guys, I included @Ginden 's fix in my PR #34
I also included many other crucial fixes such as misexamples in the README.md and following the single responsibility principle and getting some things off this package's hands
I ran into problems when trying to use this module. I added the following code for debugging:
I expected to see the program output
true
, but I instead sawfalse
!After spending hours tracing the problem down I found that another library was doing the following:
I'm not sure why this particular third party library is doing this, but I feel like something should be done to prevent it since truthiness being correct is very important for any application.