scopedaccessors.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. WScript.Echo("test1: nested setter without getter");
  6. function top1() {
  7. var xx = new Object();
  8. Object.defineProperty(xx, "yy", { set: function(val) {WScript.Echo("in nested setter1"); this.val = 10;} });
  9. var z = function() {
  10. xx.yy = 20;
  11. WScript.Echo(xx.yy);
  12. }
  13. return z;
  14. }
  15. var foo = top1();
  16. foo();
  17. WScript.Echo("test2: nested setter and setter");
  18. function top2() {
  19. var xx = new Object();
  20. Object.defineProperty(xx, "yy", { get: function() { return this; },
  21. set: function(val) {WScript.Echo("in nested setter2"); this.val = 11;} });
  22. var z = function() {
  23. xx.yy = 20;
  24. WScript.Echo(xx.yy);
  25. WScript.Echo(xx.yy.val);
  26. }
  27. return z;
  28. }
  29. var foo2 = top2();
  30. foo2();
  31. WScript.Echo("test3: nested setter and setter from this");
  32. function top3() {
  33. Object.defineProperty(this, "yy", { get: function() { return this; },
  34. set: function(val) {WScript.Echo("in nested setter3"); this.val = 12;} });
  35. var z = function() {
  36. yy = 20;
  37. WScript.Echo(yy);
  38. WScript.Echo(yy.val); }
  39. return z;
  40. }
  41. var foo3 = top3();
  42. foo3();
  43. WScript.Echo("test4: closure and with");
  44. var withObj = new Object();
  45. Object.defineProperty(withObj, "tt", { get: function() { return this; },
  46. set: function(val) {WScript.Echo("in nested setter3"); this.val = 13;} });
  47. function top4(inVar) {
  48. with (inVar)
  49. {
  50. Object.defineProperty(this, "tt", { get: function() { return this; },
  51. set: function(val) {WScript.Echo("in nested setter3"); this.val = 14;} });
  52. var z = function() {
  53. tt = 20;
  54. WScript.Echo(tt);
  55. WScript.Echo(tt.val); }
  56. return z;
  57. }
  58. }
  59. var foo4 = top4(withObj);
  60. foo4();