一道变态题 Number.call.call(Number, undefined, 0) 等于什么?
Number.call.call(Number, undefined, 0) evaluates to 0. Let's break down why:
-
Number.call:callis a method available on all functions.Number.callrefers to thecallmethod of theNumberconstructor function. Remember,Numberitself is a function that can be used to convert values to numbers. -
.call(Number, undefined, 0): Here, we're usingcallagain, but this time on thecallmethod itself. The first argument tocallsets thethisvalue of the function being called. In this case, we're setting thethisvalue toNumber. The subsequent arguments (undefined,0) become the arguments passed to the function being called. -
Putting it together: We're essentially calling
Number(undefined, 0)withNumberas its ownthisvalue. TheNumberconstructor, when called withundefinedor no arguments, returns0. The second argument,0in this case, is ignored becauseNumberonly takes one argument.
Therefore, the entire expression simplifies to Number(undefined) which results in 0.
浙公网安备 33010602011771号