Q:

Executing the content of string variable as line of code in javascript?

I have something like

"_onmouseover" : "this.className=this.className.replace(' hover',
  '')";

I'm trying to execute it like

buttonObject.onmouseover = function( ) {
                window [ this.someObject.__onmouseover ] () ;      };

And I don't know how it is possible.
Let me tell you guys my scenario. I am creating this plugin to generate four types of dialogue messages in a jquery dialogue box. Those being 'Warning', 'Error', 'Note' and 'Confirm'. So lets say there are 4 spans in dom which should trigger these four.
<span id='DialogueWarning'> Warning </span> 
<span id='DialogueError'> Error </span> 
<span id='DialogueNote'> Note </span> 
<span id='DialogueConfirm'> Confirm </span>

Now lets hadle the click to show the dialogue
jQuery('#DialogueWarning').click(function(){

        var dialogue = new Dialogue({
            "type":"Warning",
            "message":"Are you sure you want to close this window without saving your changes?",
            "buttons":
            [
                {   
                    "text":"Close without saving", 
                    "_onmouseover": "this.className+=' hover'",
                    "_onmouseout":"this.className=this.className.replace(' hover', '')",
                    "bClass":"e_customButton"
                },

                {   
                    "text":"Don't Close",
                    "_onmouseover": "this.className+=' hover'",
                    "_onmouseout":"this.className=this.className.replace(' hover', '')",
                    "bClass":"e_customButton"
                }
            ],
            "closeOnBackgroundClick" : true
        });
    });

See the "_onmouseover" and _onmouseout thingy, I need those. Is there any way I can pass those in another way

A:

If you need an eval, I bet you have some problems in your application's design.
E.g. you can avoid such things:
// ...
var eventHandlers = {
    "_onmouseover" : "this.className=this.className.replace(' hover', '')"
};

// ...

eval(eventHandlers._onmouseover);

and just do it like
var eventHandlers = {
    _onmouseover: function(e) {
        this.className=this.className.replace(' hover', '');
    }
};

buttonObject.onmouseover = eventHandlers._onmouseover;

Some articles to read:
# 1
# 2
# 3

