Last active
August 8, 2020 04:43
-
-
Save itaditya/de2f01d2a3830b235b3f16d713b724d4 to your computer and use it in GitHub Desktop.
(Blog) Why named arguments are better than positional arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Implementation | |
function myCustomParseInt(objArgs) { | |
return parseInt(objArgs.item, objArgs.radix); | |
} | |
// Usage | |
const num = myCustomParseInt({ item: '100', radix: 10 }); |
Good Catch @Kremnari, fixed it. Thanks a lot!
Named arguments are an interesting pattern. I'm considering using it as part of a "dependency injection" for things like MobX actions.
I have wondered what the performance comparison is vs positional arguments though
Sorry, should've looked first...
https://jsperf.com/object-vs-positional-args
Surprisingly, nearly no difference on chrome mobile
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might want to choose ".value" or ".item" for the passed object, not both :D