Using arguments
object(使用arguments
对象)
Note: example
is defined inside try with let
which cant be accessed from outside of scope(注意: example
是在try中定义的,其中let
不能从范围外部访问)
class Point { constructor(x, y) { this.x = x; this.y = y; this.arguments = arguments; this.isNum(); } isNum() { if (this.arguments.length != 2) { throw new Error('you send more arguments') } if (typeof this.x !== 'number' || typeof this.y !== 'number') { throw new Error('point is not a number ') } } } try { let example = new Point(1, 2) console.log(example.arguments.length) } catch (e) { console.error(e) }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…