【发布时间】:2023-03-18 15:37:01
【问题描述】:
我需要自定义错误。如果参数不是数字并且参数 alength 大于或小于 2,则会发生错误。
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
this.isNum();
}
isNum() {
if(typeof this.x !== 'number' || typeof this.y !== 'number' ) {
throw new Error('point is not a number ')
}
console.log(arguments.length)
}
}
try{
let example = new Point(1,2)
} catch(e){
console.error(e)
}
console.log(example.arguments.length)
我如何知道参数的长度?
这个拼写错了吗?
如果你能说明如何正确解决?
如果我写错了问题,我深表歉意。
【问题讨论】:
标签: javascript exception error-handling