简体   繁体   中英

How to automate the creation of "this." variables in Angular

Working on Javascript and more particulary Angular, I regulary use the this. syntax.

I'd like to know if I could concatenate variables to obtain a this. variable.
For example is that is doable?

let variable = 'variable1';
let test = 'this.' + variable
test = false

My goal would be to automate the creation of this. variables.

Thank you very much for your help !

I think there is no reason to do this. With your way you are just initializing strings in variables and then overwrite them with a boolean.

In my opinion its good for readability and understanding to see "this.", which means the following is from this class you are in at the moment. If there isn't proper code highlighting it can be confusing without it. I think you just need to get comfortable with it, but doing something like you want to feels like working around the language and not with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM