例如,假设我有一个使用节点分类的函数:
这不能正常工作,如何将对象属性作为参数传递给函数?我尝试在网上查找,但我认为我没搜到正确的信息,因为我找不到任何帮助。无论如何,提前致谢 :)
function example(){
var exampleVar = nodes.classfication;
//below i use exampleVar to do calculations
.
.
.
.
}
但是有时候我想获取节点的状态,所以我会这样做:
function example(){
var exampleVar = nodes.status;
//below i use exampleVar to do calculations
.
.
.
.
}
我不想重复编写代码,因为在我的函数中有很多代码需要重复使用。所以根据我想要从这个函数中获取什么,我会像这样将它传递给函数:
function example(thisAttribute){
var exampleVar = nodes.thisAttribute; //using the variable passed to the function
//below i use exampleVar to do calculations
.
.
.
.
}
这不能正常工作,如何将对象属性作为参数传递给函数?我尝试在网上查找,但我认为我没搜到正确的信息,因为我找不到任何帮助。无论如何,提前致谢 :)