Is it possible to do something like the following in js?
function Something( Point{PointX, PointY} ) {
console.log('Point', Point);
console.log('PointX,PointY', PointX, PointY);
}
Something([1,2]);
If so, what would be the proper way to do that?
function Something(Point) {
const [PointX, PointY] = Point
console.log('Point', Point)
console.log('PointX,PointY', PointX, PointY)
}
Is this what you need?
function Something([PointX, PointY]) {
console.log('PointX,PointY', PointX, PointY);
}
You can destructure both arrays (function([x, y]) and objects (function({ x, y })).
Sure, but make sure the keys match up to do the destructuring assignment for an object, such as:
function Something({x,y}) {
console.log('PointX, PointY', x, y);
}
Something({x: 1, y: 2});
In terms on naming and also assigning it to the outer object, perhaps you can do something like this instead:
function Something(Point) {
const {x,y} = Point;
console.log('Point, PointX, PointY', Point, x, y);
}
Something({x: 1, y: 2});