[英]Assign an object to property using 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这样的辅助对象
您不需要auxObj
,只需像样例一样调用即可:
callOtherFunction({
propertyName: functionReturnObject(),
propertyAge: 20,
sex: 'M',
test: function() {
// some process
return 0;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.