Pale Moon 27.9.2, unlike at least Chrome, Edge and IE, still does not support functions inside blocks (for example, "if") in scripts:
"SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function"
I suggest to fix it.
js: allow functions in blocks (ES6)
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.
This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.
Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.
This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.
Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
js: allow functions in blocks (ES6)
Last edited by pmuser2 on 2018-06-11, 20:54, edited 2 times in total.
Re: js: allow functions in blocks (ES6)
As per https://developer.mozilla.org/en-US/doc ... trict_mode , functions can't be defined inside blocks when using strict mode.
Pale Moon is behaving as expected.
If you want block-level functions, make sure your script is not in strict mode.
Pale Moon is behaving as expected.
If you want block-level functions, make sure your script is not in strict mode.
Re: js: allow functions in blocks (ES6)
Defining functions inside conditionals is really bad practice, you should never do this.
Instead, consider assigning functions to variables:
In sloppy mode in browsers, function statements are permitted "everywhere". This is not part of ES5 (or even ES3)! It's an extension with incompatible semantics in different browsers, meaning your results may differ depending on which browser you're using. You don't want that
Instead, consider assigning functions to variables:
Code: Select all
var a = function() { /code/ };
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite
Re: js: allow functions in blocks (ES6)
I can admit that it's bad practice. It's semantically strange.
On the other hand, JavaScript as a whole is strange. Function-inside-if seems logical to me when it's needed only on some condition.
But, from the specification point of view, it's there since 2015, year and language, ECMA-262 6th Edition.
Until ES 6, block could really contain only statements. Beginning with ES 6, block can contain both statements and declarations:
http://ecma-international.org/ecma-262/ ... #sec-block
http://ecma-international.org/ecma-262/ ... #sec-block
http://ecma-international.org/ecma-262/ ... #sec-block
I'm against programs' overcomplication. Let's just be honest and state, e.g., that Pale Moon will unlikely support that particular feature. But one shouldn't deny it's normative existence.
On the other hand, JavaScript as a whole is strange. Function-inside-if seems logical to me when it's needed only on some condition.
But, from the specification point of view, it's there since 2015, year and language, ECMA-262 6th Edition.
Until ES 6, block could really contain only statements. Beginning with ES 6, block can contain both statements and declarations:
http://ecma-international.org/ecma-262/ ... #sec-block
http://ecma-international.org/ecma-262/ ... #sec-block
http://ecma-international.org/ecma-262/ ... #sec-block
I'm against programs' overcomplication. Let's just be honest and state, e.g., that Pale Moon will unlikely support that particular feature. But one shouldn't deny it's normative existence.
Re: js: allow functions in blocks (ES6)
I'm not stating anything of that sort because it's incorrect and I won't be goaded into making statements that can be abused by opponents of our effort to repeat a few more times that "we're an obsolete firefox" which is incorrect on so many levels.
FYI: Function definitions can be placed in blocks in Pale Moon in non-strict mode (but with the limitation that they need to be defined before they are used!).
Instead I will state:
ES6 support to almost its full potential will be present in Pale Moon 28, including block-level function support where declarations don't have to be at the top of the block.
You can verify this by looking up the kangax ECMAScript support table from our unstable version of the browser.
FYI: Function definitions can be placed in blocks in Pale Moon in non-strict mode (but with the limitation that they need to be defined before they are used!).
Instead I will state:
ES6 support to almost its full potential will be present in Pale Moon 28, including block-level function support where declarations don't have to be at the top of the block.
You can verify this by looking up the kangax ECMAScript support table from our unstable version of the browser.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite
Re: js: allow functions in blocks (ES6)
Yes, it works in unstable.
As for mode, strict is "true", non-strict is not.
Thank you for the answer. I should have checked unstable version before posting.
As for mode, strict is "true", non-strict is not.
Thank you for the answer. I should have checked unstable version before posting.