object assign 用途 Posted on 2021-05-22 为对象添加属性 为对象添加方法 浅克隆 合并多个对象 属性指定默认值 1234567const DEFAULTS = { logLevel: 0, outputFormat: 'html'};function processContent(options) { let options = Object.assign({}, DEFAULTS, options);} Object.create()、new Object()和{}的区别直接字面量创建 123456789101112131415var objA = {};objA.name = 'a';objA.sayName = function() { console.log(`My name is ${this.name} !`);}// var objA = {// name: 'a',// sayName: function() {// console.log(`My name is ${this.name} !`);// }// }objA.sayName();console.log(objA.__proto__ === Object.prototype); // trueconsole.log(objA instanceof Object); // true new关键字创建 123456789var objB = new Object();// var objB = Object();objB.name = 'b';objB.sayName = function() { console.log(`My name is ${this.name} !`);}objB.sayName();console.log(objB.__proto__ === Object.prototype); // trueconsole.log(objB instanceof Object); // true Object.create 创建 https://juejin.cn/post/6844903917835436045#heading-0 https://juejin.cn/post/6844903589815517192