4 ms·
> var isNode = typeof process !== "undefined" && > {}.toString.call(process) === "[object process]"; WHAT DO YOU THINK YOU'RE RUNNING FROM?! T
by pje 12y ago
> var isNode = typeof process !== "undefined" &&
> {}.toString.call(process) === "[object process]";
WHAT DO YOU THINK YOU'RE RUNNING FROM?! THE DISEASE IS INSIDE OF YOU!
- pekk 12y agoCan you clarify?
- oblio 12y agoWell, back off from your Javascript knowledge a little and try to figure out if the intention of the code is readable. As an outsider is seems... cryptic.
- xionon 12y agoThat, and it was a chance to reference an Achewood comic, instead of an XKCD one http://achewood.com/index.php?date=07052007 http://achewood.com/index.php?date=07052007
- Touche 12y agoIt's definitely cryptic but stuff like this always happens in dynamic languages. They couldn't have created a process.thisIsNodeJS_NoForRealItIs because anything could fake it. My making it part of the toString it can't be overwritten.
- voyou 12y agoWho cares if it's being "faked", though? The code should just check directly for the existence of process.nextTick, not use a bunch of obfuscatory nonsense to check that the string representation of some object matches some arbitrary string from which you might be able to conclude that you're running on node, from which you can then conclude that you might have access to process.nextTick.
- Touche 12y agoBecause Node doesn't own process.nextTick. It's valid for a library to create one in the browser. If I'm writing JS that can be run in Node or the browser I want to know if it's REALLY IS Node or not.