bind.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 PropertyExists(obj, propName)
  6. {
  7. return obj.hasOwnProperty(propName);
  8. }
  9. var val = 100;
  10. function IncrVal()
  11. {
  12. telemetryLog(`IncrVal:: ${this.val} args.length : ${arguments.length}`, true);
  13. this.val++;
  14. return this.val + " " + arguments.length;
  15. }
  16. var fGlobalThis1 = IncrVal.bind();
  17. var fGlobalThis2 = IncrVal.bind(this);
  18. var fGlobalThis3 = IncrVal.bind(this, 50);
  19. var fGlobalThisNull = IncrVal.bind(null);
  20. var objWithVal1 = { val : 200 }
  21. var fLocal1 = IncrVal.bind(objWithVal1);
  22. var x = 20;
  23. var y = 30;
  24. function add()
  25. {
  26. return this.x + this.y;
  27. }
  28. var o = { x: 5, y: 6};
  29. var f = add.bind(o);
  30. var f2 = new f();
  31. WScript.SetTimeout(testFunction, 50);
  32. /////////////////
  33. function testFunction()
  34. {
  35. telemetryLog(`global object 1 ${fGlobalThis1()}`, true);
  36. telemetryLog(`global object 1 ${fGlobalThis1(10,20)}`, true);
  37. telemetryLog(`global object 2 ${fGlobalThis2()}`, true);
  38. telemetryLog(`global object 2 ${fGlobalThis2(10,20)}`, true);
  39. telemetryLog(`global object 3 ${fGlobalThis3()}`, true);
  40. telemetryLog(`global object 3 ${fGlobalThis3(10,20)}`, true);
  41. telemetryLog(`global object null ${fGlobalThisNull(10,20)}`, true);
  42. telemetryLog(`local length ${fLocal1.length}`, true);
  43. telemetryLog(`Local object2 ${fLocal1(10)}`, true);
  44. telemetryLog(`Add Test ${add()}`, true);
  45. telemetryLog(`f Test ${f()}`, true);
  46. telemetryLog(`Proto Test ${add.prototype.isPrototypeOf(f2)}`, true);
  47. emitTTDLog(ttdLogURI);
  48. }