(oldObject, newObject)
| 270 | * @return {Array} 包含变化属性信息的数组,每个元素是一个对象,包含 key, oldValue 和 newValue |
| 271 | */ |
| 272 | export function compareObjects(oldObject, newObject) { |
| 273 | const changedProperties = []; |
| 274 | |
| 275 | // 比较两个对象的属性 |
| 276 | for (const key in oldObject) { |
| 277 | if (oldObject.hasOwnProperty(key) && newObject.hasOwnProperty(key)) { |
| 278 | if (oldObject[key] !== newObject[key]) { |
| 279 | changedProperties.push({ |
| 280 | key: key, |
| 281 | oldValue: oldObject[key], |
| 282 | newValue: newObject[key], |
| 283 | }); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | return changedProperties; |
| 289 | } |
| 290 | |
| 291 | // playground message |
| 292 |
no outgoing calls
no test coverage detected