closure_binding_2.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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("Scenario: testing binding to the closure");
  6. function f()
  7. {
  8. x = 12;
  9. this.get = function()
  10. {
  11. WScript.Echo("x = " + x);
  12. return x;
  13. }
  14. this.set = function(n)
  15. {
  16. WScript.Echo("Setting x to " + n);
  17. x = n;
  18. }
  19. // Declare the variable at the lexical end of the scope to
  20. // make the binding tougher for the byte code generator.
  21. var x;
  22. }
  23. var x = new f();
  24. var y = new f();
  25. for(i = 0; i < 4; ++i)
  26. {
  27. x.set(i);
  28. y.set(i+100);
  29. x.get();
  30. y.get();
  31. }