deferredWith.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 test0(x) {
  6. with (x)
  7. {
  8. z =
  9. function handlerFactory() {
  10. return { test:
  11. function () { return "4"; } };
  12. },
  13. z2 =
  14. function handlerFactory2() {
  15. return {
  16. test:
  17. function a() { return "5"; }
  18. };
  19. }
  20. };;
  21. var handlerFactory = handlerFactory || undefined;
  22. var handlerFactory2 = handlerFactory2 || undefined;
  23. return { x: x, handlerFactory: handlerFactory, handlerFactory2: handlerFactory2 };
  24. };
  25. var p={o:1, z:2, z2:3};
  26. WScript.Echo("p = " + JSON.stringify(p));
  27. var testOut=test0(p);
  28. var k = testOut.x;
  29. WScript.Echo("k = " + JSON.stringify(k));
  30. WScript.Echo("k.z = " + k.z);
  31. WScript.Echo("k.z() = " + k.z());
  32. WScript.Echo("k.z().test() = " + JSON.stringify(k.z().test()));
  33. WScript.Echo("k.z().test()+1 = " + JSON.stringify(k.z().test()+1));
  34. WScript.Echo();
  35. WScript.Echo("sibling with block");
  36. WScript.Echo("k.z2 = " + k.z2);
  37. WScript.Echo("k.z2() = " + k.z2());
  38. WScript.Echo("k.z2().test() = " + JSON.stringify(k.z2().test()));
  39. WScript.Echo("k.z2().test()+1 = " + JSON.stringify(k.z2().test() + 1));
  40. WScript.Echo();
  41. WScript.Echo("compat mode specifics as !== undefined (if present) - version:2 specifics");
  42. if (testOut.handlerFactory !== undefined) {
  43. WScript.Echo("testOut.handlerFactory().test() = " + JSON.stringify(testOut.handlerFactory().test()) + " (as json)");
  44. WScript.Echo("testOut.handlerFactory().test()+1 = " + testOut.handlerFactory().test() + 1);
  45. }
  46. if (testOut.handlerFactory2 !== undefined) {
  47. WScript.Echo("testOut.handlerFactory2().test() = " + JSON.stringify(testOut.handlerFactory2().test()) + " (as json)");
  48. WScript.Echo("testOut.handlerFactory2().test()+1 = " + testOut.handlerFactory2().test() + 1);
  49. }