Asif
Asif

Reputation: 393

How to convert string variable to namespace object

I have a javascript service CoreAdapterService. Within that code there are a lot of literal references to CoreAdapterService namespace which I want to replace with a var.

I have tried declaring a var at the top of the service and use it in the service as shown in code sample but no luck. Any help welcome

enter image description here

Upvotes: 1

Views: 482

Answers (1)

Dirk-Jan
Dirk-Jan

Reputation: 1149

I am sorry it seems like my previous answer was incorrect, you are currently trying to get a var inside your object. The function you are executing has another scope so it is unable to reach the variable. A possible solution would be to define your variable above your adapter. Then the following code should work.

Try the following:

var definition = this[adapterNameSpace].service[service];

This way you are gettings this.CoreAdapterService.services[service];

Upvotes: 2

Related Questions