Loading ...
Sorry, an error occurred while loading the content.

Re: "use strict" for libraries

Expand Messages
  • douglascrockford
    ... It depends on the Require use strict ; option. You have it set, so JSLint expects to see use strict ; as the first line of the file. If you turn the
    Message 1 of 2 , Sep 2 10:50 AM
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "aseem.kishore@..." <aseem.kishore@...> wrote:
      >
      > A lot of libraries are written inside one big, anonymous wrapper function:
      >
      > (function () {
      > // ...
      > }());
      >
      > As I understand from John Resig's post on "use strict" <http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/>, a library author can place "use strict" inside that wrapper function:
      >
      > "A neat aspect of being able to define strict mode within a function is that you can now define complete JavaScript libraries in a strict manner without affecting outside code. [...] A number of libraries already use the above technique (wrapping the whole library with an anonymous self-executing function) and they will be able to take advantage of strict mode very easily."
      >
      > (function () {
      > "use strict";
      > // ...
      > }());
      >
      > But this doesn't pass JSLint, as it expects "use strict" to be at the very top, outside the function:


      It depends on the Require "use strict"; option. You have it set, so JSLint expects to see "use strict"; as the first line of the file. If you turn the option off, then you can place it at the first line of a function instead.
    Your message has been successfully submitted and would be delivered to recipients shortly.