How can I call properties within the datasets
object itself, in this case to create fullName
with already existing data?
calling this.
shouldn't work? When i'm try occurs > "Uncaught TypeError: Cannot read properties of undefined (reading 'firstName')"
Script:
var datasets = {
cst_TEST: {
firstName: "John",
lastName: "Deacon"
},
glb_TEST: { age: "30" },
fullName: this.cst_TEST.firstName + " " + this.cst_TEST.lastName
}
var kOBJ = {
fxAAA(){ console.log("First Name: " + datasets.cst_TEST.firstName); },
fxBBB(){ console.log("Last Name: " + datasets.cst_TEST.lastName); },
fxCCC(){ console.log("Age: " + datasets.glb_TEST.age); },
fxDDD(){ console.log("Full Name: " + datasets.fullName); }
}
Output:
<script>
kOBJ.fxAAA(); //output: `First Name: John`
kOBJ.fxBBB(); //output: `Last Name: Deacon`
kOBJ.fxCCC(); //output: `Age: 30`
kOBJ.fxDDD(); //output (should be): `Full Name: John Deacon` - err: Uncaught TypeError: Cannot read properties of undefined (reading 'firstName')
</script>