with3.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. function test1() {
  7. var obj = {};
  8. var x = "test1_value";
  9. function foo() {
  10. return x;
  11. }
  12. with (obj) {
  13. write(foo());
  14. }
  15. }
  16. test1();
  17. function test2() {
  18. var obj = {};
  19. function foo() {
  20. return "test2_value";
  21. }
  22. var o1 = { f : foo };
  23. with (obj) {
  24. write(o1.f());
  25. }
  26. }
  27. test2();
  28. function test3_helper() { return "test3_helper"; }
  29. function test3() {
  30. var o = {};
  31. with (o)
  32. {
  33. var g = test3_helper;
  34. var x = g();
  35. write(x);
  36. }
  37. }
  38. test3();
  39. var test4_obj = { prop4: "Feb20" };
  40. with (test4_obj) {
  41. write("test4_obj.prop4 = " + (0, function () {
  42. return (0, function () {
  43. return prop4;
  44. })()
  45. })())
  46. }
  47. var test5_obj = {};
  48. with (test5_obj) {
  49. test5_obj.func5 = function (x) {
  50. write(helper5);
  51. var func5_inner = function (d, c) {
  52. write("func5_inner " + x);
  53. write(helper5);
  54. };
  55. func5_inner();
  56. };
  57. test5_obj.helper5 = function helper_5(a, b) {
  58. write("in pair entry");
  59. };
  60. }
  61. var result5 = test5_obj.func5(100);
  62. write(result5);
  63. var test6_result = "global test6_result";
  64. function test6() {
  65. function test6_inner() {
  66. return this.test6_result;
  67. }
  68. with ({})
  69. write(test6_inner());
  70. }
  71. test6();