Add multiple attributes to an existing js object

前端 未结 6 1016
不知归路
不知归路 2020-12-31 01:50

I want to add multiple attributes to an existing object with existing attributes. Is there a more concise way than one line per new attribute?

myObject.name         


        
6条回答
  •  -上瘾入骨i
    2020-12-31 02:15

    In ECMAscript 5 you can make us of defineProperties:

    Object.defineProperties(myobject, {  
      name: {  
        value: 'don' 
      },  
      gender: {  
        value: 'male' 
      }  
    });
    

提交回复
热议问题