MySQL_Narb Posted January 12, 2014 Share Posted January 12, 2014 Here is bossScenario: var bossScenario = { 'active': false, 'scenario_ID':0, 'boss': {} }; Here is a list of scenarios: var scenarios = { 1 : { 'func' : function(bossDifficulty){ /*var me = bossScenario['boss'][1]; var vars = me['vars']; vars[rbSoldiers] = bossDifficulty*100000; vars[reward] = bossDifficulty;*/ alert('test'); //randBossBattle(vars); }, 'vars' : { rbSoldiers : 0, reward : 0 } } } In bossScenario, I will assign a scenario to the 'boss' property. And then I will run the below code: bossScenario['boss'][sID]['func'](bossDifficulty); The above code will successfully alert "test"; however, next time I go to run the function, I get this error in the console: Uncaught TypeError: Object #<Object> has no method 'func' It's as if the 'func' property and its function are being removed from the bossScenario function after it is ran. Why is this? Quote Link to comment https://forums.phpfreaks.com/topic/285297-function-in-object-keeps-disappearing-after-being-executed/ Share on other sites More sharing options...
Solution MySQL_Narb Posted January 12, 2014 Author Solution Share Posted January 12, 2014 This has been solved. JSON does not parse functions! Quote Link to comment https://forums.phpfreaks.com/topic/285297-function-in-object-keeps-disappearing-after-being-executed/#findComment-1464897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.