Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S.equals不能处理function对比 #624

Closed
superfighter opened this issue May 15, 2014 · 5 comments
Closed

S.equals不能处理function对比 #624

superfighter opened this issue May 15, 2014 · 5 comments

Comments

@superfighter
Copy link

S.equals({'h':{'h':'123',g:[123],t:function(){}}},{'h':{'h':'123',g:[123],t:function(){}}});
结果是false
可否在object判断之前加上
if (typeof a === 'function' && typeof b === 'function') {
return (a.toString() === b.toString());
}
这样就正常对比了。

@yiminghe
Copy link
Member

不能这么做,toString() 不可靠,不准确

function mix(){}.toString() !== function(){}.toString()

@superfighter
Copy link
Author

对,不能让equals这么做。

@superfighter
Copy link
Author

动equals是不合理的,那么在compareObjects里做判别如何?对象的属性不会出现function mix(){}的情况吧。
if (typeof a[property] === 'function' && typeof b[property] === 'function') {
if(a[property].toString() !== b[property].toString()){
mismatchValues.push('functions were not the same');
}
} else if (!S.equals(a[property], b[property], mismatchKeys, mismatchValues)) {
mismatchValues.push('"' + property + '" was "' +
(b[property] ? (b[property].toString()) : b[property]) +
'" in expected, but was "' +
(a[property] ? (a[property].toString()) : a[property]) + '" in actual.');
}

@yiminghe
Copy link
Member

不要搞两个的 function,用一个function两个引用

@superfighter
Copy link
Author

那怎么才能完美的做到把function也判别在内呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants