可可

文章 评论 浏览 26

可可 2022-05-04 13:56:53

规范
15.4.4.7 Array.prototype.push ( [ item1 [ , item2 [ , … ] ] ] )

The arguments are appended to the end of the array, in the order in which they appear. The new length of the array is returned as the result of the call.

When the push method is called with zero or more arguments item1, item2, etc., the following steps are taken:

  1. Let O be the result of calling ToObject passing the this value as the argument.
  2. Let lenVal be the result of calling the [[Get]] internal method of O with argument "length".
  3. Let n be ToUint32(lenVal).
  4. Let items be an internal List whose elements are, in left to right order, the arguments that were passed to this function invocation.
  5. Repeat, while items is not empty
  6. Remove the first element from items and let E be the value of the element.
  7. Call the [[Put]] internal method of O with arguments ToString(n), E, and true.
    Increase n by 1.

调用对象O 的 [[Put]] 内部方法,传参为 ToString(n) (键名),E(值),true,然后 n 增加 1

  1. Call the [[Put]] internal method of O with arguments "length", n, and true.
    Return n.
  2. The length property of the push method is 1.

NOTE The push function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the push function can be applied successfully to a host object is implementation-dependent.

第七步是原因

第 46 题:输出以下代码执行的结果并解释为什么?

可可 2022-05-04 13:55:04

http1.0不支持持久连接
http1.1支持持久连接,但是串行发送请求,并行请求只能同时建立多个tcp连接,引入了管道化,但是存在队头阻塞的问题
http2.0二进制分帧、多路复用、头部压缩、服务端推送

第 117 题:介绍下 http 1.0、1.1、2.0 协议的区别?

可可 2022-05-04 13:54:12

为啥感觉你们写的怎么这么复杂 。。。

Promise.retry = function (promiseFunc, num = 2) {
  return promiseFunc().then(null, (e) => {
    if (num > 0) {
      num -= 1;
      console.log("重试");
      return Promise.retry(promiseFunc, num);
    }
    return Promise.reject(e);
  });
};

再简化一下

Promise.retry = function (promiseFunc, num = 2) {
  return promiseFunc().then(null, (e) => num > 0 ? Promise.retry(promiseFunc, num - 1) : Promise.reject(e));
};

第 159 题:实现 Promise.retry,成功后 resolve 结果,失败后重试,尝试超过一定次数才真正的 reject

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文