最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SyntaxError: 'with' statements are not valid in strict mode - Stack Overflow

programmeradmin1浏览0评论

I'm getting this error in safari console when I try to do anything from a breakpoint. Bug report here: .cgi?id=83267

Does anyone have a workaround? For reasons that I am assuming are related to this javascript has ceased to run on my site in safari.

edit: the bug report also contains repro steps.

another edit: I'm not using a "with" statement. This is a bug from the safari console.

I'm getting this error in safari console when I try to do anything from a breakpoint. Bug report here: https://bugs.webkit.org/show_bug.cgi?id=83267

Does anyone have a workaround? For reasons that I am assuming are related to this javascript has ceased to run on my site in safari.

edit: the bug report also contains repro steps.

another edit: I'm not using a "with" statement. This is a bug from the safari console.

Share Improve this question edited Oct 25, 2016 at 13:56 Damjan Pavlica 34k10 gold badges75 silver badges78 bronze badges asked Aug 31, 2012 at 16:04 quinnquinn 5,99810 gold badges36 silver badges54 bronze badges 3
  • 1 Not Safari-specific. 'use strict';with(this); in FF/Chrome produces "strict mode code may not contain 'with' statements". – Rob W Commented Aug 31, 2012 at 16:11
  • 11 It is specific to Safari in that if you try to evaluate anything in the debugger console within a "use strict"; scope, you get this error, even if you can't see the word with anywhere in your script or in what you've typed. Apparently Safari wraps whatever you've typed in a with and tries to evaluate it. See the referenced bug report for more details. – Kristopher Johnson Commented Jan 23, 2013 at 1:01
  • 1 possible duplicate of Can't inspect scope variable when using strict mode – Lance Fisher Commented Jan 13, 2014 at 22:55
Add a comment  | 

2 Answers 2

Reset to default 9

The with(obj) {} statement is deprecated, and as such, is not valid in strict mode.

To solve this, either disable strict mode, or stop using with statements!

Strict mode in ECMAScript 5 bans eg. with statement. You have two choices:

  • disable strict mode (remove "strict mode"; line from the file / function), or
  • (preferred) avoid using with statements - they are harmful and totally unreadable.

More on strict mode from John Resig: ECMAScript 5 Strict Mode, JSON, and More.

You can read in the article, that strict mode:

  • makes you unable to delete variable (like in delete foo;),
  • limits usage of eval,
  • adds some limitations to functions (eg. accessing caller and callee),
  • removes with statements,
发布评论

评论列表(0)

  1. 暂无评论