calling
calling

Reputation: 15

Enforcing strict mode retroactively

I'd like to enforce function level strict mode (i.e. toggle strict to true in the project's .jshintrc) on a legacy javascript project. Is there any way to do this aside from adding a "use strict"; line at the start of every single function in my project?

For any project (new or old) it seems like a lot of avoidable boilerplate. How do people (if at all) typically handle it?

Upvotes: 1

Views: 51

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074485

...aside from adding a "use strict"; line at the start of every single function in my project?

Yes, you can add it at the top of every file in the project (this is the "code compilation" level); it applies to all functions within the file (code compilation unit).

This is also true for inline script in web pages, FWIW, e.g.:

<script>
"use strict";
// This is strict mode code
function foo() {
    // So is this
}
</script>
<script>
// This isn't
</script>

Upvotes: 2

Related Questions