Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用对象文字语法将对象指定给属性_Javascript_Object Literal - Fatal编程技术网

Javascript 使用对象文字语法将对象指定给属性

Javascript 使用对象文字语法将对象指定给属性,javascript,object-literal,Javascript,Object Literal,我需要使用对象文字语法将一个对象作为属性传递给另一个对象,如下所示: var obj = functionReturnObject(); callOtherFunction({propertyName: obj}); 我知道还有其他简单的方法可以做到这一点,例如 var obj = functionReturnObject(); var auxObj= {}; auxObj.propertyName = obj ; callOtherFunction(auxObj); 或 我想知道是否有任何

我需要使用对象文字语法将一个对象作为属性传递给另一个对象,如下所示:

var obj = functionReturnObject();
callOtherFunction({propertyName: obj});
我知道还有其他简单的方法可以做到这一点,例如

var obj = functionReturnObject();
var auxObj= {};
auxObj.propertyName = obj ;
callOtherFunction(auxObj);


我想知道是否有任何直接的方法可以在文字语法中做到这一点,以避免使用像auxObj这样的辅助对象,您不需要
auxObj
,只需像您的示例一样调用:

callOtherFunction({
   propertyName: functionReturnObject(), 
   propertyAge: 20, 
   sex: 'M', 
   test: function() {
      // some process
      return 0;
   }   
});

您这样的东西很好,
callOtherFunction({propertyName:obj})有什么问题
callOtherFunction({propertyName:functionReturnObject()})?请查看第二条路径下方的注释。在使用callOtherFunction()之前,我需要保留该对象的副本。所以我可以这样做:
var obj=functionReturnObject()
callOtherFunction({propertyName:functionReturnObject()})但性能不好,因为functionReturnObject()是一个非常重的函数。@gsc delmo请看Alex K发表的第一条评论。使用
var obj=functionReturnObject();callOtherFunction({propertyName:obj})对不起,各位,我在浏览器中以错误的方式测试此问题。我将对你的评论投赞成票。谢谢。
callOtherFunction({
   propertyName: functionReturnObject(), 
   propertyAge: 20, 
   sex: 'M', 
   test: function() {
      // some process
      return 0;
   }   
});