Created
April 17, 2017 06:56
-
-
Save qzm/2ddac17dd22fde16b09cadc894e9dc06 to your computer and use it in GitHub Desktop.
判断两个值是否相等
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if two values are loosely equal - that is, | |
* if they are plain objects, do they have the same shape? | |
*/ | |
function looseEqual(a, b) { | |
var isObjectA = Object.prototype.toString.call(a) === '[object Object]'; | |
var isObjectB = Object.prototype.toString.call(b) === '[object Object]'; | |
if (isObjectA && isObjectB) { | |
return JSON.stringify(a) === JSON.stringify(b) | |
} else if (!isObjectA && !isObjectB) { | |
return String(a) === String(b) | |
} else { | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment