Created
April 21, 2013 07:59
-
-
Save moriiimo/5428825 to your computer and use it in GitHub Desktop.
呼び出し元の引数を別の関数内で書き換えることができる。(IE限定)
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html lang="ja"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<meta http-equiv="Content-Style-Type" content="text/css"> | |
<meta http-equiv="Content-Script-Type" content="text/javascript"> | |
<title>IEだけでできること:呼び出し元の引数を壊す</title> | |
<script type="text/javascript" src="../js/lib/jquery-1.9.1.min.js"></script> | |
<link rel="stylesheet" type="text/css" href="../css/style.css"/> | |
</head> | |
<body> | |
<script> | |
$(function () { | |
function func1(bool) { | |
func2(); | |
console.log(bool); // false と出力したい。 | |
} | |
function func2() { | |
func2.caller.arguments[0] = false; // ここでfunc1の仮引数boolの値をfalseにできる。IEだけfalseになる。 | |
// https://developer.mozilla.org/ja/docs/JavaScript/Reference/Global_Objects/Function/caller | |
} | |
func1(true); | |
}); | |
</script> | |
<div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment