5 ms·
Shouldn't that just be the only and correct way, then? No need for .toString() magic..
by lerouxb 13y ago
Shouldn't that just be the only and correct way, then? No need for .toString() magic..
- ahuth 13y agoSure, that makes sense to me. Looks like I misunderstood the author's intent. This should be the only way, though. Also, I didn't even realize that this way doesn't require .toString magic.
- lerouxb 13y agoActually I'm not 100% sure it that it doesn't require toString magic at all, but it would at least require less and probably be more reliable.
- aidos 13y agotoString is only used to parse the function signature to get the list of dependencies. If you use the other syntax it doesn't have to do the "magic" at all. I haven't looked at the output (though the magic function itself is pretty simple) but I would imagine it just creates the explicit version that you can choose to write manually. I'm a little torn myself; on the one hand, I prefer explicit code without magic. Having said that, you often need quite a few dependencies and it's a pain, and ugly, to write them all out twice on all your signatures.
- ahuth 13y agoAgreed. And at least it's more clear that dependencies are being injected.
- Cthulhu_ 13y agoThen again, reading about Angular's DI for a few minutes should lock this convention into your mind pretty quickly, I think. An array of strings where the last entry is a function that takes arguments named after the strings of the array it's defined in... sounds rather hacky and confusing to me, not to mention it duplicates strings. Easy to make a typo, easy to change the order of arguments - and no compiler or any kind of sensible IDE or tool to warn you about it.
- AdrianRossouw 13y agoit doesn't need the toString this way, because it's already a string being passed in.