letconst_global.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 print(x) { WScript.Echo(x+''); }
  6. function filter(name) {
  7. return /^[a-z]$/.test(name) || /^shadow_(let|const)$/.test(name);
  8. }
  9. print('\n==== Basic let and const variables at global scope ====\n');
  10. // Since the let/const globals are implemented as special properties
  11. // in the [Simple]DictionaryTypeHandler, try out the other types of
  12. // global properties to sanity check that they are still property-
  13. // like (on global object, enumerable)
  14. var a = 'global var a';
  15. b = 'global undecl b';
  16. let c = 'global let c';
  17. const d = 'global const d';
  18. function e () { }
  19. print('\nNaked references\n');
  20. print(a);
  21. print(b);
  22. print(c);
  23. print(d);
  24. print(e);
  25. print('\nthis. references\n');
  26. print(this.a);
  27. print(this.b);
  28. print(this.c);
  29. print(this.d);
  30. print(this.e);
  31. print('\nfor-in enumeration of this\n');
  32. for (let p in this)
  33. {
  34. if (filter(p))
  35. {
  36. print(p + ': ' + this[p]);
  37. }
  38. }