Meta_Data Meta_Data - 1 month ago 5
Javascript Question

Adding + to the dictionary in javascript

I want to create a dictionary in javascript like this

var operations=
{
first: function(x)
{
return x[0];
}
}


How can I add the + operation as key to the dictionary that will point to the + operation in javascript? The same thing was done in python by operator.add . How can do it in Javascript?

var operations=
{
+ : return + operation in javascript //syntax is not valid

first: function(x)
{
return x[0];
}
}


.

Answer

Use "+"

var operations=
{  
     "+"    :     return + operation in javascript //syntax is not valid

     first:     function(x) 
                 {
                    return x[0];
                 }
}