zloirock / core-js

Standard Library
MIT License
24.59k stars 1.66k forks source link

About your core.js :packages/core-js/internals/function-bind.js #1341

Closed agustHLX closed 7 months ago

agustHLX commented 7 months ago

When you try to write the source code for bind at this file path, I have a question. Since https://tc39.es/ecma262/#sec-function.prototype.bind clearly states that the function returned by bind does not have a “prototype”, and my actual test found that the prototype of bound is indeed undefined,.why do you still write boundFunction.prototype = Prototype; to make the prototype of the returned function point to the prototype of the original method? Why not directly boundFunction.prototype = undefined? I guess you want to take into account the situation with the new keyword, so that the prototype of the object created by new points to the Prototype of the original method; Can we find a better way to do this? For example, specifying the Prototype of boundFunction based on the result of this instanceof boundFunction? Thank you very much for your answer and help. If there is a better solution, please let me know at any time. Once again, I appreciate your patience and guidance.

zloirock commented 7 months ago

Thanks for the issue. It was already discussed some times, you could find the answer, for example, here: https://github.com/zloirock/core-js/issues/1293#issuecomment-1733255260

agustHLX commented 7 months ago

Okay, thank you. That's a tricky question. Have a nice day!