I'm trying to achieve a snippet corresponding to an example found in this book. Here my Javascript snippet: "use strict"
function readObject(target, name, descriptor) {
return console.log("reading object...: ", target, name, descriptor)
}
class Example {
a() {}
@readObject
b() {}
}
const e = new Example();
e.a = 1;
e.b = 2;
My console returns:
line 12 _ SyntaxError: illegal character
I have also tried:
function readonly(target, name, descriptor) {
descriptor.writable = false;
return descriptor;
}
class Example {
a() {}
@readonly
b() {}
}
const e = new Example();
e.a = 1;
e.b = 2;
the later trial fails too.
It seems to me I have defined readObject
.
Maybe I have forgot an another element?
Any hint would be great, thanks.