C # converter for JavaScript: ((object) sender). attribute

4

I'm developing a C # to JavaScript converter and I'm in a bind when the code has a line of code like this:

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

What is the corresponding JavaScript code?

    
asked by anonymous 25.05.2015 / 14:41

1 answer

3

See, in C #, you're saying:

((ImageButton) sender) .ImageUrl

- Grab the object "sender" and make a Cast pro type 'ImageButton'; - With the resulting object (which is an instance of ImageButton), get the ImageUrl property (which is part of the ImageButton type);

Well, javascript is a poorly typed language. This cast is unnecessary. If the object is of ImageButton type, the ImageUrl property will be there, without you needing the cast. It will suffice:

sender.ImageUrl.

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

    
10.06.2015 / 20:42