I would like to know whats wrong with following JavaScript code –
<html>
<script type="text/javascript">
var p = eval('new { "Color":"Red"}');
alert(p.Color);
</script>
</html>
It is giving me JavaScript error as –
Message: Object doesn't support this action
Line: 4
Char: 1
Code: 0
There are several problems with the code;
firstly you’re telling the script to create something new, but you’re not telling it what to create. If you aren’t creating a custom object, you are creating an Object object, so you need to tell it that:
Now that you are creating a new Object object, you can configure the Color property:
Here is a working fiddle
But, why are you using eval in the first place? eval is evil!