在 docker-compose.yml 中定义这样的设备映射时:
version: "3.8"
services:
app:
build: .
devices:
- /dev/video0:/dev/video0
Run Code Online (Sandbox Code Playgroud)
如果在主机系统上没有 /dev/video0 的情况下启动此容器,容器将崩溃并出现以下错误:
Error response from daemon: error gathering device information while adding custom device "/dev/video0": no such file or directory
我想确保当在类外更改对象的属性时引发错误。这是我尝试执行的操作:
class Example {
constructor(index) {
this.index = index;
Object.defineProperty(this, 'index', {
set() {
throw new AssertionError("can't set attribute");
}
});
}
}
class AssertionError extends Error {
constructor(message) {
super();
this.name = "AssertionError";
this.message = message;
}
}
let example = new Example(5);
console.log(example.index); //prints undefined instead of 5
example.index = 10; // I want to throw an AssertionError hereRun Code Online (Sandbox Code Playgroud)
就像我想要的那样抛出错误,但是索引值未定义。我仍然希望能够在类内部更改属性,但是我想防止属性在类外部更改。