functional.js 630 B

1234567891011121314151617
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export function once(fn) {
  6. const _this = this;
  7. let didCall = false;
  8. let result;
  9. return function () {
  10. if (didCall) {
  11. return result;
  12. }
  13. didCall = true;
  14. result = fn.apply(_this, arguments);
  15. return result;
  16. };
  17. }