Switch2.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. var x = { i : 1, j : 2, k : 3 };
  6. switch(x.i)
  7. {
  8. case "1":
  9. WScript.Echo("error - found \"1\"");
  10. break;
  11. default:
  12. WScript.Echo("error - found default");
  13. break;
  14. case 1.000000001:
  15. WScript.Echo("error - found 1.000000001");
  16. break;
  17. case 1:
  18. WScript.Echo("found 1");
  19. break;
  20. }
  21. switch(x.q)
  22. {
  23. case undefined:
  24. WScript.Echo("found undefined");
  25. break;
  26. default:
  27. WScript.Echo("found a value");
  28. }
  29. x.f = function() { this.j++; return this.j; }
  30. q();
  31. function q() {
  32. switch(x.j)
  33. {
  34. case 1:
  35. WScript.Echo("error - found 1");
  36. return;
  37. case x.f():
  38. WScript.Echo("error - found x.f()");
  39. return;
  40. case 2:
  41. WScript.Echo("found 2, x.j = " + x.j);
  42. return;
  43. case 3:
  44. WScript.Echo("error - found 3");
  45. return;
  46. }
  47. }
  48. var y = new Object();
  49. y.z = x;
  50. y.w = x;
  51. switch(x)
  52. {
  53. case y.w:
  54. WScript.Echo("found y.w");
  55. break;
  56. case y.z:
  57. WScript.Echo("found y.z");
  58. break;
  59. }