TApply1.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 test(x) {
  6. WScript.Echo("test apply simple call with one argument: " + x );
  7. }
  8. test.apply(null, ["val1", "val2", "val3"]);
  9. function test1(x, y, z) {
  10. WScript.Echo("test apply simple call with 3 arguments: " + x + " , " + y + " , " + z);
  11. }
  12. test1.apply(null, ["p1", "p2", "p3"]);
  13. function test2(x, y) {
  14. WScript.Echo("In test2 apply ");
  15. this.a = x;
  16. this.b = y
  17. }
  18. var o1 = new Object();
  19. test2.apply(o1, [9, "secondValue"]);
  20. WScript.Echo("test apply call to function that sets properties in 'this': " + o1.a + " , " + o1.b );
  21. function test3() {
  22. WScript.Echo("In test3 apply ");
  23. this.a = "param1";
  24. this.b = 99
  25. }
  26. test3.apply();
  27. WScript.Echo("test apply call to function that sets properties in global 'this': " + a + " , " + b);
  28. function testArg(x, y, z) {
  29. WScript.Echo("**run tests with Arguments object");
  30. test.apply(null, arguments);
  31. test1.apply(null, arguments);
  32. var o1 = new Object();
  33. test2.apply(o1, arguments);
  34. WScript.Echo("test apply call to function that sets properties in 'this': " + o1.a + " , " + o1.b);
  35. }
  36. testArg("1stArg", "2ndArg", "3rdArg");