使用Object Literal Syntax将对象分配给属性

时间:2014-05-28 16:45:07

标签: javascript object-literal

我需要使用Object Literal Syntax将对象作为属性传递给其他对象,如下所示:

var obj = functionReturnObject();
callOtherFunction({propertyName: obj});

我知道还有其他简单的方法可以做到这一点,例如

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

callOtherFunction({propertyName: functionReturnObject()});
//This way is not useful for me because I need to keep a copy of the object before use it as parameters to the function callOtherFunction()

我想知道在文字语法中是否有任何直接的方法可以避免使用像auxObj这样的辅助对象

1 个答案:

答案 0 :(得分:0)

您不需要auxObj,只需像样本一样打电话:

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