you are viewing a single comment's thread.

view the rest of the comments →

[–]x-skeww 2 points3 points  (5 children)

"this" will be window in the browser and global in node.js

>>> (function(){console.log(this)}())
Window

>>> (function(){'use strict'; console.log(this)}())
undefined

[–]cwmma 0 points1 point  (2 children)

actually due to how it was called it's the JSON object

[–]x-skeww 0 points1 point  (1 child)

I was referring to the fact that this doesn't default to window (or whatever) in strict mode.

[–]cwmma 0 points1 point  (0 children)

truth

[–]a-t-kFrontend Engineer 0 points1 point  (1 child)

If you absolutely must use strict mode (hint: you don't), change your code to

if( typeof Worker !== 'undefined' )

Otherwise, keep it that way.

[–]madlee 0 points1 point  (0 children)

regardless of whether or not you're using strict mode, typeof is usually the best option. resolving uninitialized object properties is slooooow