This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 13985 - JavaScript uses "strict mode" but depends on "this" in function context
Summary: JavaScript uses "strict mode" but depends on "this" in function context
Status: RESOLVED FIXED
Alias: None
Product: mobileOK Basic checker
Classification: Unclassified
Component: Web interface (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: fd
QA Contact: fd
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-01 07:35 UTC by fd
Modified: 2011-09-01 11:55 UTC (History)
0 users

See Also:


Attachments

Description fd 2011-09-01 07:35:44 UTC
In "strict mode", "this" is not set anymore to the global context in a function. It remains "undefined" for security reasons.

In other words, the following code should result in "glob" set to "undefined" in browsers that support strict mode:

"use strict";
(function () {
  var glob = this; // "glob" is "undefined", not the global context
})();

This bug went unnoticed up until now because Web browsers simply did not implement that feature. Latest versions of Chrome, Firefox and possibly others apply that rule correctly, though, making the JavaScript crash.
Comment 1 fd 2011-09-01 11:55:27 UTC
Scoping function now executed with ".call(this)" to set the function context to the global context. Another similar bug fixed in mobileok.js