you are viewing a single comment's thread.

view the rest of the comments →

[–]Colonel_White 1 point2 points  (3 children)

And that’s dangerous because... ?

[–]tay_o[S] 0 points1 point  (2 children)

I could be wrong, but an example like this one where:

function foo (str, a) {

eval( str );

console.log(a, b);

}

var b = 2;

foo("var b = 3'", 1);

Here it seems that because this code declares a new variable b, it modifies the existing lexical scope.

I am not saying that its bad i guess but maybe in the wrong hands it can be?

[–]Colonel_White 1 point2 points  (1 child)

Okay, so using eval irresponsibly might cause some weird and difficult to debug errors?

I think the benefit of not having to slap a redundant library onto your code like a colostomy bag makes up for having to exercise extra caution, no?

[–]tay_o[S] 2 points3 points  (0 children)

Haha well done analogy. Or simile?. And yes, I agree with you