I found this code in some library, which tries to avoid hard-coding window
object:
var global = (function () {
return this || (1, eval)('this');
}());
Anybody can explain the meaning of "|| (1,eval)('this')
" part? And why to use (1,eval)
instead of just eval
?
Asked
Active
Viewed 27 times
2
Engineer
- 43,887
- 11
- 83
- 90
-
(1,eval) is an indirect eval, which breaks out of a custom function with a custom _this_ when applying the code. – dandavis Feb 28 '15 at 09:07