【发布时间】:2013-05-28 18:00:37
【问题描述】:
如果属性未定义,我希望属性抛出错误,如this question。该问题的每个答案都建议使用 Python 的 @property 装饰器在未定义该字段时引发异常。我如何在 JS 中做到这一点?
编辑:
我希望相当于:
var MyObj = {
method: function(){
throw new Error('This method is not implemented');
}
};
...但更接近:
var MyObj = {
attribute: throw new Error('This attribute is not defined');
};
【问题讨论】:
标签: javascript decorator