僕の備忘録(PC、UN*X、ネットワーク関連が中心)なんです。
自分の書いたところは適当(な時とか)に書き換えますので御了承を。
オブジェクト同士の比較。例によって<html> とか <Script type="text/JavaScript">の類は省略。
var foo = {baz: 'quux'}; var bar = {baz: 'quux'}; var qux = foo; document.write(foo, "<br>"); document.write(bar, "<br>"); document.write(qux, "<br>"); document.write("<br>"); document.write("foo.baz is", foo.baz ,"<br>"); document.write("bar.baz is", bar.baz, "<br>"); document.write(foo.baz == bar.baz, "<br>"); document.write(foo == bar, "<br>"); document.write(foo == qux, "<br>");
[object Object] [object Object] [object Object] foo.baz is quux bar.baz is quux true false true
間違ってたらしい。 関数の中の関数の中で宣言された変数は、そこでしか 使えない。
<html> <script type="text/JavaScript"> function print() { var max = arguments.length; var i; for (i = 0; i < max; i++) document.write(arguments[i], " "); document.write("<br>"); } function foo(opt) { var bar = opt + 1; print ("in function foo, bar is ", bar); function baz(opt2) { var qux = opt2 + 2; print ("in function baz that in fucntion foo, qux is ", qux); } baz(bar); print("in function foo, qux is", "qux" in window); } foo(2) print("in global, bar is", "bar" in window); print("in global, qux is", "qux" in window); </script> </html>
in function foo, bar is 3 in function baz that in fucntion foo, qux is 5 in function foo, qux is false in global, bar is false in global, qux is false
リンクはご自由にどうぞ。でもURLや内容が変った場合はあしからず。