tags:

views:

57

answers:

1

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?

+1  A: 

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.

Kevin
I thought ,I can call this Calculator object from my C# dynamic keyword
Amutha
No not if the Calculator object is written in JavaScript.
Kevin
Now,I can understand the real use of Dynamic
Amutha