Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to pass array element name?
Message
De
01/12/2015 11:49:16
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01628031
Message ID:
01628159
Vues:
30
>>>>>>comments can be misleading: untested
>>>>>>
>>>>>>function MyTest( cCol1Name ) {
>>>>>>var MyObject = .... object is created
>>>>>>var Row = MyObject[0].cCol1Name;
>>>>>>var Col1Val = Row[cCol1Name]
>>>>>>// var Col1Val = eval( "Row." + cCol1Name)
>>>>>>}
>>>>>>>>>
>>>>>
>>>>>Thank you.
>>>>
>>>>The commented eval() should work as well, but is considered by some to be an anti-pattern. Was a bit short in my explanation ;-)
>>>
>>>I am very much a newbie to javascript. So I will look up this function; use, upside and downside. One thing I found so far is that javascript is very unforgiving. If I have ANYTHING wrong in my javacript (like, e.g., missing the ending ";") nothing works in the code. And no error appears when I am running it in ASP.NET. I have to be extra careful.
>>
>>Just to throw one more option at you:
>>Take a look at Typescript. It's compiles to javascript and is very good at catching errors at that point. Also allows you to define type-safe classes in a C# fashion...
>
>Thank you. I will Google for "Typescript".

It's a MS add-on for Visual Studio. Easy to get started since it can use your existing .js files - just rename them to .ts. That in itself won't do much but, for example, you can then specify the type for javascript variables and it will enforce type safety.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform