1. window.fetch = function () {
    2. const args = FetchHook.fetchArgs(arguments);
    3. // do something else
    4. }
    5. static fetchArgs (args: IArguments) {
    6. let arg0: Request;
    7. let arg1: RequestInit;
    8. const result = {
    9. url: '',
    10. method: 'GET',
    11. headers: {}
    12. };
    13. // 这里会报错,因为 args 是 Iarguments,需要有callee
    14. // callee指向arguments对象的拥有函数引用
    15. args = Array.prototype.slice.apply(args);
    16. args.length > 0 && (arg0 = args[0]);
    17. args.length > 1 && (arg1 = args[1]);
    18. arg0 && typeof arg0 === 'string' && (result.url = arg0);
    19. if (arg0 && typeof arg0 === 'object') {
    20. result.url = arg0.url;
    21. result.method = arg0.method;
    22. }
    23. if (arg1 && typeof arg1 === 'object') {
    24. result.method = arg1.method || result.method;
    25. result.headers = {
    26. 'Pinpoint-TraceID': PinPoint.getTraceId(),
    27. ...arg1.headers,
    28. };
    29. }
    30. return result;
    31. }

    image.pngimage.png
    可以使用 es6 的解构赋值处理
    image.png