You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some decorator can modify a class method to require a "secret" first argument before calling the host method
constsafe=secret=>fn=>function(passedSecret, ...args){if(passedSecret!==secret){throwError('Wrong password sir');}returnfn.apply(this,args);};constsecret=Symbol();classFoo{
#bar;getBar(){returnthis.#bar;}}// Current way of decorationFoo.prototype.getBar=safe(secret)(Foo.prototype.getBar);constfoo=newFoo();foo.getBar();// Errorfoo.getBar(anyOtherSymbol)// Also errorfoo.getBar(secret)// Voilà
In the future we can also use the new decorator syntax
classBar{
@safe(secret)setBar(newValue){// ...}}
One problem is that it adds the complexity to having to call the method with another argument
The other problem is that it looses the static analyzable property of the current syntax. In my opinion Javascript per se don't need this kind of static analyzable syntax (not yet at least), we already have a lot of static typed languages that do a pretty good job at preventing typos and restricting member permissions, it would be a lot more fitting if this languages implemented some type of module scoped access (in fact there's already ongoing discussions about the subject)
Anyway, I think this proposal is in the right direction, keep up with the good work!
The text was updated successfully, but these errors were encountered:
Some decorator can modify a class method to require a "secret" first argument before calling the host method
In the future we can also use the new decorator syntax
One problem is that it adds the complexity to having to call the method with another argument
The other problem is that it looses the static analyzable property of the current syntax. In my opinion Javascript per se don't need this kind of static analyzable syntax (not yet at least), we already have a lot of static typed languages that do a pretty good job at preventing typos and restricting member permissions, it would be a lot more fitting if this languages implemented some type of module scoped access (in fact there's already ongoing discussions about the subject)
Anyway, I think this proposal is in the right direction, keep up with the good work!
The text was updated successfully, but these errors were encountered: