开发者

C# Dynamic Keyword and Javascript

Suppose i have a javascript

<script language="javascript">

var Calculator =function ADD(int x,int y)
         开发者_开发问答       {
                  return x+y;
                }

</script>

(1) using dynamic keyword how can i access the "ADD()" and pass parameters?

(2) Do i need to refer any namespace in order to achieve it?


I think you are mixing up languages.

The dynamic keyword is in C#. You'll need to pass the C# variable values to the browser if you want JavaScript to add the numbers. If you want to add in javascript you have to do something like:

<script language = "JavaScript" >

var Calculator =function ADD(int x,int y)
                {
                  return x+y;
                }


 Calculator('<%=Value1.ToString()%>', '<%=Value2.ToString()%>');

</script>

This is assuming Value1 and Value2 are numbers (int, short etc.);

http://www.hanselman.com/blog/C4AndTheDynamicKeywordWhirlwindTourAroundNET4AndVisualStudio2010Beta1.aspx

Looking at the blog entry, you can do it if there is a .net implementation of the language (like python) using the dynamic keyword.

EDIT: Here is a link to the CodePlex project to put a JavaScript implementation on top of the DLR.

http://javascript.codeplex.com/

With this, using the dynamic keyword should be possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜