Your SlideShare is downloading. ×
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

"strict mode": (not) everything you ever wanted to know about JavaScript's strict mode

1,484

Published on

A 30-minute presentation given at Dealer.com on May 6, 2011. …

A 30-minute presentation given at Dealer.com on May 6, 2011.

An overview of what "strict mode" means ECMAScript 5, and what it means (and does not mean) for everyday web development.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,484
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • ( Firefox has had it for quite some time… Chrome and Safari have it now… IE9? )
  • Invoked as either- The first line in a whole JS file –or-- As the first line in a function
  • Enforcing some rules that were common sense… and/or were not exactly built-in but should have been……and/but then we get to the controversy? (who in here has seen 'undefined' get defined as such for the sake of old IE versions?)
  • But this isn't much of a controversy? - - restrictions on eval() are a blessing
  • But this might get some hackles up… There's that whole bit about `this` being "broken" in JavaScriptBut if you're expecting `this` to scope up to `window`… now you have broken code
  • Firefox 4 will complain:'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
  • it's opt-in – so you'd have to decide to use itAnd anyway it's just enforcing certain coding styles that you ought to be doing anywayAnd/but you're already linting right?And/but there is an argument to be made for NOT using it
  • Transcript

    • 1. “strict mode”
      (Not) Everything You Ever Wanted to Know About JavaScript's Strict Mode
    • 2. Just What is this so-called “strict mode”?
      What can it do for me? …or TO ME?
    • 3. “Strict Mode” is…
      • Introduced as part of ECMA-262 (5th Ed.)
      • 4. Quickly becoming an available option in major browsers
      • 5. “A slight augmentation” of how ECMAScriptengines interpret/execute code
      • 6. “Like a seatbelt for your code” in that it tries to protect you from yourself
    • Sometimes known as…
      (colloquially, of course)
    • 7. “Crockford Mode”
    • 8. What about some concrete Examples?
    • 9. "strict mode";
      // and then the rest
      // but be careful when
      // concatenating!
      // "more compatible" way:
      (function(){
      "use strict";
      // and then the rest
      })();
      How do I invoke it?
    • 10. // "old" way
      foo = 'is now global';
      "use strict";
      bar = 'is not global';
      // throws a ReferenceError
      Won’t let you do dumb things:implicit globals
    • 11. // "old" way
      foo = {
      bar: function(){},
      baz: 'name'
      };
      with(foo){
      bar(baz);
      }
      "use strict";
      foo = {
      bar: function(){},
      baz: 'name'
      };
      with(foo){
      bar(baz);
      }
      // ERROR!
      Won’t let you do dumb things:WITH(){}
    • 12. …and other things you know better than to try and do in the first place.
      "use strict";
      delete undeclaredVariable; // ERROR!
      var foo = { eval: function(val){} }; // ERROR!
      var arguments = somethingGlobal; // ERROR!
      varNaN = 'not a number'; // ERROR!
      var Infinity = (getAllNaturalNumbers() / 2); // ERROR!
      var undefined = 'undefined'; // ERROR!
    • 13. // "old" way
      eval("that = 'this and that!';");
      console.log('that is...:', that);
      "use strict";
      eval("that = 'this and that!';");
      console.log('that is...:', that);
      // ERROR!
      Not without controversy
    • 14. // "old" way
      (function(){
      console.log(
      'this is...:',
      this
      );
      })();
      // this == window
      "use strict";
      (function(){
      console.log(
      'this is...:',
      this
      );
      })();
      // this == undefined
      Not without controversy
    • 15. Not without controversy
      "use strict";
      function factorial(num){
      if (num <= 1) {
      return 1;
      } else {
      return num * arguments.callee(num-1);
      }
      }
      // ERROR!
    • 16. What does it mean for me?
    • 17. What does it mean for me?
      (probably nothing)
    • 18. Read More
      • Mark Miller, WaldemarHorwat, and Mike Samuel: “Changes to JavaScript, Part 1: EcmaScript 5”
      • 19. http://ajaxian.com/archives/ecmascript-5-changes-to-javascript
      • 20. Video: http://www.youtube.com/watch?v=Kq4FpMe6cRs
      • 21. Angus Croll: “JavaScript Strict Mode”
      • 22. http://javascriptweblog.wordpress.com/2011/05/03/javascript-strict-mode/
      • 23. MDC: ECMAScript 5 support in Mozilla
      • 24. https://developer.mozilla.org/En/JavaScript/ECMAScript_5_support_in_Mozilla
      • 25. Douglas Crockford: “Strict Mode is Coming to Town”
      • 26. http://www.yuiblog.com/blog/2010/12/14/strict-mode-is-coming-to-town/

    ×