如何将实例化对象的属性作为参数传递给 JavaScript 函数。我想这样做,以便我被迫始终使用对象的相同属性。
我该怎么做呢?
//object
var house = {
bed:"",
chair:"",
tv,""
};
//function
var doThis = function(OBJ){
//pass this OBJ to something
alert(OBJ.bed);
alert(OBJ.chair);
alert(OBJ.tv);
};
//call function
doThis({new house.bed = "a", new house.chair="c", new house.tv = "f"});
doThis({new house.bed = "dd", new house.chair="gg", new house.tv = "jjjh"});
doThis({new house.bed = "ff", new house.chair="hh", new house.tv = "hhh"});
doThis({new house.bed = "gg", new house.chair="jjj", new house.tv = "hh"});