一道变态题 Number.call.call(Number, undefined, 0) 等于什么?

Number.call.call(Number, undefined, 0) evaluates to 0. Let's break down why:

  1. Number.call: call is a method available on all functions. Number.call refers to the call method of the Number constructor function. Remember, Number itself is a function that can be used to convert values to numbers.

  2. .call(Number, undefined, 0): Here, we're using call again, but this time on the call method itself. The first argument to call sets the this value of the function being called. In this case, we're setting the this value to Number. The subsequent arguments (undefined, 0) become the arguments passed to the function being called.

  3. Putting it together: We're essentially calling Number(undefined, 0) with Number as its own this value. The Number constructor, when called with undefined or no arguments, returns 0. The second argument, 0 in this case, is ignored because Number only takes one argument.

Therefore, the entire expression simplifies to Number(undefined) which results in 0.

posted @ 2024-12-08 09:02  王铁柱6  阅读(9)  评论(0)    收藏  举报