I want to have a function that can auto match the variable name inside of an object and apply them to the local variable if the name matched.
I am currently using this way, but as the variable increasing I want to actually make a new function to apply them.
ob = { a: 1, b: 2, }
-----------------------------
Install(ob)
function Install(ob){
if('a' in ob) a = ob.a;
if('b' in ob) b = ob.b;
}
var a; var b;
I want something can do like this
function Install(ob){
for( // each ob`s this varaiable name){
if (//this name much local variable name){
//local varaible = ob this variable
}
}
}
Is this possible? Thank you very much for your advice.
If you just want to make top level global variables out of all properties of an object (which I’m unsure why you would do), you can do that like this:
Otherwise, please explain better what you’re actually trying to accomplish.