I have a bunch of classes that are called with varying amounts of arguments:
class Square {
height;
width;
constructor(height, width) {
this.height = height;
this.width = width;
}
}
Instances of these classes are stored in an array to keep a timeline of them:
const sq = new Square(22, 23);
const history = [sq];
I would like to find a way of getting the arguments from the classes constructor, this is as far as I got:
history[0].contructor.arguments
Which results in an error:
VM448:1 Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at :1:24
I want to get the contents of the arguments keyword from the constructor (so the array like object that has both the height and width arguments).
I realise I could use a super class and extend it in all of the classes I need this functionality from, but ideally would like to avoid modifying them. Any ideas?
this._arguments = [...arguments]?