C# to Javascript Converter: ((object)Sender). attribute

Asked

Viewed 288 times

4

I’m developing a C# to Javascript converter and I’m in a jam when the code has a line of code like this:

((CONTROLE)sender).Atributo 
Exemplo:((ImageButton)sender).ImageUrl

What is the corresponding Javascript code?

1 answer

3

See, in C#, you’re saying:

((Imagebutton)Sender). Imageurl

-Grab the "Sender" object and cast it for type 'Imagebutton'; -With the resulting object (which is an instance of 'Imagebutton'), take the Imageurl property (which is part of the Imagebutton type);

Well, javascript is a weakly typed language. This cast is unnecessary. If the object is of the Imagebutton type, the Imageurl property will be there without you needing the cast. Simply:

Sender.Imageurl.

If you need to confirm the cast, use typeof to check the instance class.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.