scopeFunction.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 outer(val)
  6. {
  7. var iic = val + 1;
  8. function inner() { return iic++; }
  9. return inner;
  10. }
  11. var fouter = outer(3);
  12. var gouter = outer(5);
  13. function ctr(val)
  14. {
  15. var iic = val;
  16. this.inc = function () { return iic++; }
  17. this.dec = function () { return iic--; }
  18. }
  19. var fctr = new ctr(3);
  20. var fctr2 = fctr;
  21. var gctr = new ctr(5);
  22. WScript.SetTimeout(testFunction, 50);
  23. /////////////////
  24. function testFunction()
  25. {
  26. ////
  27. fouter();
  28. ////
  29. telemetryLog(`fouter(): ${fouter()}`, true); //5
  30. telemetryLog(`gouter(): ${gouter()}`, true); //6
  31. ////
  32. fctr.inc();
  33. ////
  34. telemetryLog(`fctr.inc(): ${fctr.inc()}`, true); //4
  35. telemetryLog(`gctr.inc(): ${gctr.inc()}`, true); //5
  36. ////
  37. fctr2.dec();
  38. fctr2.dec();
  39. ////
  40. telemetryLog(`post decrement -- fctr.inc(): ${fctr.inc()}`, true); //3
  41. telemetryLog(`post decrement -- gctr.inc(): ${gctr.inc()}`, true); //6
  42. emitTTDLog(ttdLogURI);
  43. }