Length.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function write(v) { WScript.Echo(v + ""); }
  6. var o = new Object();
  7. o.length = 10;
  8. write(o.length + " " + o["length"] + " " + o["len" + "gth"]);
  9. o.length = 20;
  10. write(o.length + " " + o["length"] + " " + o["len" + "gth"]);
  11. var s = "Hello World";
  12. write(s.length + " " + s["length"] + " " + s["len" + "gth"]);
  13. var x = s.length = 30;
  14. write(x);
  15. write(s.length + " " + s["length"] + " " + s["len" + "gth"]);
  16. var o1 = new Object();
  17. var a = [1000,2000,3000];
  18. // Normal index
  19. write(a[0] + " " + a["0"] + " " + a[0.0]);
  20. // 'x' Expando
  21. a.x = 40;
  22. write(a.x + " " + a["x"]);
  23. // object o as expando
  24. a[o] = 50;
  25. write(a[o] + " " + a[o1] + " " + a["[object Object]"] + " " + a["[object" + " Object]"]);
  26. // array length
  27. write(a.length + " " + a["length"] + " " + a["len" + "gth"]);
  28. a.length = 60;
  29. write(a.length + " " + a["length"] + " " + a["len" + "gth"]);
  30. a["length"] = 70;
  31. write(a.length + " " + a["length"] + " " + a["len" + "gth"]);
  32. a["le" + "ngth"] = 80;
  33. write(a.length + " " + a["length"] + " " + a["len" + "gth"]);
  34. function foo() {};
  35. write(foo.length + " " + foo["length"] + " " + foo["len" + "gth"]);
  36. function foo1(x) {};
  37. write(foo1.length + " " + foo1["length"] + " " + foo1["len" + "gth"]);
  38. function foo2(x,y,z) {};
  39. write(foo2.length + " " + foo2["length"] + " " + foo2["len" + "gth"]);
  40. eval("function foo3(x,y){};");
  41. write(foo3.length + " " + foo3["length"] + " " + foo3["len" + "gth"]);