我无法找到让这种事情发挥作用的方法:
// I want to achieve managing the structure of the object here and only here
var objectAPropertiesList = ["aProp", "bProp", "cProp"];
// Object with constructor
function ObjectA(properties) {
objectAPropertiesList.forEach(function (property) {
this[property] = properties[property];
});
}
// instantiation
myObjectA = new ObjectA({"aProp": 1, "bProp": 2, "cProp": 3});
// keeps giving me '{}' !
console.log(JSON.stringify(myObjectA));
有人可以解释一下吗?