Created
November 2, 2010 02:35
-
-
Save torus/659186 to your computer and use it in GitHub Desktop.
Comparing with structure and Function.call method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>with vs Function.call</title> | |
</head> | |
<body> | |
<p>See JavaScript console using Chrome developer tool or Firebug.</p> | |
<script id="script"> | |
console.log ("using with..."); | |
var a = {value_a: "a"}; | |
var b = {value_b: "b"}; | |
with (a) { | |
with (b) { | |
console.log (this); | |
console.log (value_a); | |
console.log (value_b); | |
} | |
} | |
console.log ("using Function.call..."); | |
(function () { | |
console.log (this); | |
console.log (this.value_a); | |
console.log (value_a); // Error on Chrome | |
}).call (a) | |
</script> | |
<h2>Source</h2> | |
<script> | |
var e = document.createElement ("pre"); | |
e.textContent = document.getElementById ("script").innerHTML; | |
document.body.appendChild (e); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment