I am currently working on a "simple" tax calculator that gets some information from a database and the web page it is currently on hosted on. For example, you are on a property page that has details about your home. It would find specific pieces of information: tax district, property type, and current value to name a few. On top of this, the database has some changing information that is entered through an admin interface to develop the tax formula.
I am experimenting with eval to process the formula that is return from the database via jsonp. The issue I am running into is how can I get the eval function to recognize that the variables that the formula is comprised of are in the "calculator" object.
Example json results:
var calculator = {
  "Name": "Residential",
  "Formula": "(((rrb * (base + iv) - (hcv * homestead)) - (mcv * military)) * (levy / 1000))",
  "Levy": 1000.00000,
  "Variables": [
    {
      "Type": "System",
      "DisplayName": "Tax District",
      "ShortName": "levy",
      "Value": 0.000000
    },
    {
      "Type": "Form Variable",
      "DisplayName": "Current Property Value",
      "ShortName": "currentValue",
      "Value": 0.000000
    },
    {
      "Type": "Form Variable",
      "DisplayName": "Number of Homestead Credits",
      "ShortName": "homestead",
      "Value": 0.000000
    },
    {
      "Type": "Form Variable",
      "DisplayName": "Number of Military Credits",
      "ShortName": "military",
      "Value": 0.000000
    },
    {
      "Type": "Rollback",
      "DisplayName": "Residential Rollback",
      "ShortName": "rrb",
      "Value": 0.528200
    },
    {
      "Type": "User Input",
      "DisplayName": "Total Value Add of Improvements",
      "ShortName": "iv",
      "Value": 0.000000
    },
    {
      "Type": "Credit",
      "DisplayName": "Homestead Credit Value",
      "ShortName": "hcv",
      "Value": 4850.000000
    },
    {
      "Type": "Credit",
      "DisplayName": "Military Credit Value",
      "ShortName": "mcv",
      "Value": 1852.000000
    }
  ]
}
With the above object, the formula used with eval, will only look at the global namespace, but I really don't want to expose the variables that way.
What is the easiest way to get this to play nicely with eval? Ideally, I could have some function I pass the object into and it would make the values easily available to the eval function.
 
     
     
    