Underscore.JS isEqual方法
语法
_.isEqual(object, other)
isEqual方法对一个对象与其他对象进行深度比较。看下面的示例:
示例
var _ = require('underscore');
var student = {name: 'Sam', age: 10, class: { name: '10th', section: 'B'}}
var student1 = {name: 'Sam', age: 10, class: { name: '10th', section: 'B'}}
// Example: Compare student with student1 using ==
console.log(student == student1);
var result = _.isEqual(student, student1);
console.log(result);
将上面的程序保存在 tester.js 中。运行以下命令以执行该程序。
命令
>node tester.js
输出
false
true