It's Possible now with ASP.Net MVC4 Razor View engine. the code will be this:
// c# class
public class A
{
public string Hello(string msg)
{
return msg + " whatewer";
}
}
// js snippet
and Razor isn't just for MVC4 or another web applications and you can use it in offline desktop applications.