javascript - How can an object literal's property be assigned to the return value of one of its methods? -


so making game practice using mvc paradigm. create object literal model , want functions needs generate values properties in object itself. have tried no success. have tried using "this" when calling function , not using it. either way, function not defined error chrome. can fix this? here's relevant code:

var model = { genplayers: function() {         return tempplayerarray;     },  playerarray: genplayers() } 

you can't that. 1. there no function name genplayers() model.genplayers() , 2. object properties can't accessed during object initialization.

what is:

var model = {     genplayers: function() {         return tempplayerarray;     },     playerarray: null };  model.playerarray = model.genplayers(); 

or if model.genplayers returns tempplayerarray this:

var model = {     genplayers: function() {         return tempplayerarray;     },     playerarray: tempplayerarray }; 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -