We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Object.is = function (x, y) { if (x === y) { // 当前情况下,只有一种情况是特殊的,即 +0 -0 // 如果 x !== 0,则返回true // 如果 x === 0,则需要判断+0和-0,则可以直接使用 1/+0 === Infinity 和 1/-0 === -Infinity来进行判断 return x !== 0 || 1 / x === 1 / y; } // x !== y 的情况下,只需要判断是否为NaN,如果x!==x,则说明x是NaN,同理y也一样 // x和y同时为NaN时,返回true return x !== x && y !== y; };
The text was updated successfully, but these errors were encountered:
function myIs(x, y) { // 判断是否是同一对象(包括 +0/-0) if (x === y) { return x !== 0 || 1 / x === 1 / y; } else { // 判断是否是 NaN return x !== x && y !== y; } }
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: