<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta charset="utf-8" /> <title>Object.assign 是目标参数修改后返回 </title> </head> <body> </body> </html>
var obj0 = {}; var obj1 = { a: 1, b: 2 }; console.debug("obj0", obj0) console.debug("obj1", obj1) var result1 = Object.assign({}, obj1); console.debug("copy obj1", result1) Object.assign(obj0, obj1) console.debug("obj0", obj0, 'target obj0 changed')