accessor.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  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 = { foo: 3, bar: null };
  6. Object.defineProperty(x, "b", {
  7. get: function () { return this.foo + 1; },
  8. set: function (x) { this.foo = x / 2; }
  9. });
  10. Object.defineProperty(x, "onlyone", {
  11. get: function () { return this.bar; }
  12. });
  13. WScript.SetTimeout(testFunction, 50);
  14. /////////////////
  15. function testFunction()
  16. {
  17. telemetryLog(`typeof (x): ${typeof (x)}`, true); //object
  18. telemetryLog(`x.foo: ${x.foo}`, true); //3
  19. telemetryLog(`x.b: ${x.b}`, true); //4
  20. telemetryLog(`x.onlyone: ${x.onlyone}`, true); //null
  21. ////
  22. x.b = 12;
  23. ////
  24. telemetryLog(`x.foo: ${x.foo}`, true); //6
  25. telemetryLog(`x.b: ${x.b}`, true); //7
  26. }