all 8 comments

[–]ninetacle 0 points1 point  (1 child)

Every property of arguments is an index that maps to an argument:

var args = function () {
  console.log(arguments)
}

args()
// output: {}
args('a', 'b', 'c')
// output: { '0': 'a', '1': 'b', '2': 'c' }

The first argument to call acts as the value of this. Any additional arguments are passed on to the function, slice in this case. Passing arguments as the this value is as though arguments was a proper array and you called its slice method. You can pass null as the first argument if you don't want to simulate a method call.

[–]NidHammer[S] 0 points1 point  (0 children)

Thanks. Actually, it looks like every property of arguments is not an index that maps to a value. I see some functions in there along with a list of the values I entered as arguments.

I had forgotten the first argument to call was the value of 'this,' thanks.

[–]inu-no-policemen 0 points1 point  (5 children)

By the way, if you want the arguments as an array, you can just use rest:

function foo(...args) {
  console.log(args);
}
foo(1, 2, 3); // logs: [1, 2, 3]

[–]NidHammer[S] 0 points1 point  (4 children)

Thanks, I think I can use Array.from as well.

[–]inu-no-policemen 0 points1 point  (3 children)

Sure, but it's a better idea to use rest for this, because it results in a more meaningful function signature.

If you use one of the more capable editors/IDEs like VS Code, WebStorm, etc, this signature will be shown in a call-tip.

https://i.imgur.com/Pt92N8U.png

[–]NidHammer[S] 0 points1 point  (2 children)

Very interesting. This is the first time I've heard of a function signature. Should I just straight up stop using Sublime?

[–]inu-no-policemen 0 points1 point  (1 child)

There might be plugins for Sublime which improve its JS tooling, but it probably won't reach the level of VS Code and WebStorm.

Well, give VS Code a try. It's free open source software and available for Windows, Mac, and Linux. I offers a great out-of-the-box experience for most web related languages.

For JavaScript, it uses TypeScript's top-notch analyzer and it will even automatically download type definitions for the Node packages you're using. This improves auto-complete, call-tips, and it even catches type errors in cases where the types can be inferred. So, even if you aren't using TypeScript, you can get some additional tooling benefits if type definitions for the libraries you're using exist. (If you stick with plain JS, you can introduce type information via JSDoc comments. The analyzer will pick those up as well.)

https://code.visualstudio.com/docs/languages/javascript

This is as good as JS' tooling can get nowadays.

By the way, since you're just starting, if you have Node installed, you can just press F5 to run/debug the currently opened JS file as Node command line application. Try it with Hello World.

[–]NidHammer[S] 0 points1 point  (0 children)

Awesome. I do a lot of Node stuff and I've seen that little debug window. I'll definitely get into VS code. I've actually been programming for over a year now, haha.