Hi consider below code
let test={
a:function(){
console.log('Hi')
}
}
Is there a way to invoke property 'a' using a variable ?
This works ,
let test={
a:function(tmp){
console.log(tmp)
}
}
let functn='a';
test[functn]("hello");
but is there anyway to invoke the same like below code :
let test={
a:function(){
console.log('Hi')
}
}
let functn='a("hello")';
test.function;
The actual use case:
This is protractor system test related question,
I have a parent object with css locator [id=1] and the child elements has the locators [id=1]>div , [id=1]>span etc.
so currently parent element is stored as
let parent = element(by.css('[id=1']) ,
child as
let child1= element(by.css('[div]')
So to find all child elements of the parent element the function is :
element(by.css('[id=1']).element(by.css('[div]')
so instead of writing the locator again, i want to achieve:
parent.child1
b = test.a; b()? Though this won't work, if the method containsthiskeyword.const fnct = {name: "a", args: ["hello"]}? With that, you can dotest[fnct.name].apply(null, fnct.args). But no,a("hello");will never work.