Skip to content

Instantly share code, notes, and snippets.

@senz
Created August 7, 2013 09:05
Show Gist options
  • Save senz/6172452 to your computer and use it in GitHub Desktop.
Save senz/6172452 to your computer and use it in GitHub Desktop.
getting global object from random places and behavior in strict mode
<html>
<body>
<script>
"use strict";
var obj = {lolo: 1};
console.log("ljambda this in strict:", (function(){ return this === undefined; })());
(function() {
console.log("current context:", this);
var Fn = Function, global = new Fn('"use strict"; return this')();
console.log("evaled func this is (strict): ", global);
var Fn = Function, global = new Fn('return this')();
console.log("evaled func this is (non-strict): ", global);
}).apply(obj);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment