One feature I use extensively in C # is delegate which is a reference type used to reference anonymous or named methods. Especially the classes already implemented in the framework such as Action and Func , as shown below.
public class Program
{
public static void Main
{
ExibirMensagem((s) =>
{
Console.WriteLine(s);
});
}
public static void ExibirMensagem(Action<T> actMensagem)
{
actMensagem("Exibiu a mensagem");
}
}
I would need something similar to this, but in JavaScript. I'm new to JavaScript and I do not know how to do this, it may even be something very simple. In Java 6 that does not support this type of behavior, I remember that to get around this and do something similar I used an interface that could be implemented anonymously, as shown below:
public interface IAcao {
void Executar(String str);
}
public class Program {
public static void Main(string[] args) {
ExecutarAcao(new IAcao() {
@Override
public void Executar(String str) {
Log.v("Exec", str);
}
});
}
public static void ExecutarAcao(IAcao delAcao) {
delAcao.Executar("Executou Ação");
}
}
Is this approach possible in JavaScript?