I want to define an object, and use a function to populate an array as one of the members of the object. I have tried using a function both inside and outside the object definition, but neither seems to work. Is this possible? Here is a simplified version of what I am trying to do:
<!DOCTYPE html>
<html>
<body>
<p>object function test.</p>
<p id="demo"></p>
<script>
var test_object = {
num1: 1,
num2: 10,
nums: make_array(this.num1, this.num2)
};
function make_array(firstnum, lastnum) {
myArray = [];
for (i=firstnum; i <= lastnum; i++){
myArray.push(i);
}
return myArray;
};
document.getElementById("demo").innerHTML = test_object.nums;
</script>
</body>
</html>
It seems that num1 and num2 are undefined
when they are passed to the function. What am I doing wrong?