Problem specifying timer as key within JSON object (inside a plugin) - Forum

Forum Navigation
You need to log in to create posts and topics.

Problem specifying timer as key within JSON object (inside a plugin)

@luishp

No hurry; so you can look into this after you return from your trip.

This works when it is part of the click event of a Push Button ...

BeginJS
var gkSweetA = {};
gkSweetA.timer = 3000;
alert(gkSweetA.timer);
EndJS

But this code as part of a plugin Action ...

var gkJSON = {};
gkJSON.timer = 2000;
alert(gkJSON.timer);

... fails to display anything at run time (including the Push Button) ... only happens when the key is timer ... works with other key names (including gkJSON.timerx)

In order to eliminate other possible causes, I have even removed the plugin file.

When it does not display (in Chrome), the console says ...

Uncaught SyntaxError: Unexpected number jquery.min.js:2

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.7.7/$injector/modulerr?p0=NeoApp&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.7.7%2F%24injector%2Fnomod%3Fp0%3DNeoApp%20%20%20%20at%20file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A7%3A168%20%20%20%20at%20file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A26%3A453%20%20%20%20at%20b%20(file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A25%3A478)%20%20%20%20at%20file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A26%3A227%20%20%20%20at%20file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A42%3A496%20%20%20%20at%20r%20(file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A8%3A76)%20%20%20%20at%20g%20(file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A42%3A344)%20%20%20%20at%20fb%20(file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A46%3A460)%20%20%20%20at%20c%20(file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A22%3A57)%20%20%20%20at%20Uc%20(file%3A%2F%2F%2FC%3A%2FProgramData%2FSinLios%2FVisualNeoWeb%2Fjs%2Fangular.min.js%3A22%3A370)
at angular.js:99
at angular.js:5060
at r (angular.js:387)
at g (angular.js:5020)
at fb (angular.js:4937)
at c (angular.js:1960)
at Uc (angular.js:1981)
at Ae (angular.js:1866)
at HTMLDocument.<anonymous> (angular.js:36424)
at l (jquery.min.js:2)

Unfortunately, timer is one of the keys I need to pass to the SweetAlert2 plugin.

@gaev, I can't reproduce the problem.
Your code works fine for me within a plugin action.
Can you send me a sample so I can check it?

Thanks!!

@luishp

As I was preparing to send you the files (devoid of all non-essential commands), I did a few tests to make sure the problem still existed.

It still exists, but I observed something that I had not observed before.

It is NOT the fact that the key was named timer that caused the problem (while timerx was fine), but the fact that I also had a plugin-command parameter named timer ... when I try ...

var gkJSON = {};
gkJSON.xxxx = 2000;
alert(gkJSON.xxxx);

... where xxxx is ALSO a parameter, I get the error situation ... change any one of them and everything is fine.

Let me know if you can't reproduce this, and I will provide the files.

Hi @gaev,
If you have used a parameter named "timer" then that word becomes a reserved word, so it can't be used again in your plugin with another meaning. I understand your JSON needs that exact name, but why can't you just change your parameter name to another one?

@luishp

I understand your JSON needs that exact name, but why can't you just change your parameter name to another one?

After I realized the real cause of the problem I was encountering, that was exactly my "workaround" plan; I was just waiting to hear from you to see if this was a restriction or some kind of bug/defect.

Thanks for the confirmation; I will add prefixes of prm to all my parameters.