Extending an object with multiple properties in JavaScript

后端 未结 3 1624
清酒与你
清酒与你 2021-02-19 16:39

I have a global JavaScript object with multiple properties and functions that I am creating it this way:

myObject = {};

I thought that I can ea

3条回答
  •  迷失自我
    2021-02-19 17:13

    When you write myObject = { ... }, you're creating a brand-new object and setting myObject to point to it.
    The previous value of myObject is thrown away.

    Instead, you can use jQuery:

    jQuery.extend(myObject, { newProperty: whatever });
    

提交回复
热议问题