JavaScript doesn’t implement parameter expansion in the way that Python does (it looks like what’s where you’re getting your inspiration). The way you invoke a function in JavaScript only ever translates into one set of arguments
:
function f() { console.log(arguments); }
f([1, 2, 3], 1);
// {0: [1, 2, 3], 1: 1}
And JavaScript allows you to define named arguments of the function to take the values of arguments[0]
, arguments[1]
, etc. The arguments are never expanded out depending on the argument type and the signature of the function. function f([a, b, c], d)
is simply not a supported syntax. You should see a SyntaxError: Unexpected token [
in the browser console. You’ve got a few options:
function Paddle(start, end) {
this._paddle_line_start = start;
this._paddle_line_end = end;
}
new Paddle([x1, y1], [x2, y2]);
function Paddle(start, end) {
this._paddle_lne_start = [start.x, start.y];
this._padde_line_end = [end.x, end.y];
}
new Paddle({x: x1, y: y1}, {x: x2, y: y2});
function Paddle(x1, y1, x2, y2) {
this._paddle_line_start = [x1, y1];
this._paddle_line_start = [x2, y2];
}
new Paddle(x1, y1, x2, y2);
Note that in the MDN documentation of Function the [
and ]
in the constructor definition denote optional arg1 through argN, not literal brackets.