I am trying to execute the following JS code:
var foo = { func1:function(){ function test() { alert("123"); }(); alert("456"); }, myVar : 'local' };
But I get an error Syntax Error: invalid property id
What is wrong with the code above?
You have a syntax error:
var foo = { func1:function() { function test() { alert("123"); }(); // ^ You can't invoke a function declaration alert("456"); }, myVar : 'local' };
Assuming you need a function called immediately, you will need to execute this function as an expression instead:
var foo = { func1:function() { (function test() { // ^ Wrapping parens cause this to be parsed as a function expression alert("123"); }()); alert("456"); }, myVar : 'local' };
wrap with () :
()
(function test(){ alert("123"); }());
Or:
(function test(){ alert("123"); })();
Source: https://habr.com/ru/post/1493637/More articles:ElementFlow element disables controls - c #How to generate domain objects using annotations using sleep mode tools - javaselect char - KDB - kdbUIButton Background Image Does Not Change - iospointer-events: none on embed / object in and due to browser inconsistencies iframe - objectOpen your own phone book as an intention and use it to search. Possible? - androidHow to open the phone book from the Android application? - androidhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1493640/count-all-subordinates-who-directly-or-indirectly-reports-to-managers&usg=ALkJrhjyP9FUadRj1_bEw6pkrHreVaEXjwHow to return marshal values โโof WinApi functions? - c #Maven version ignores includeList - mavenAll Articles