js: allow functions in blocks (ES6)

Suggestions and feature requests for the Pale Moon browser

Moderator: satrow

pmuser2
Moongazer
Moongazer
Posts: 9
Joined: Fri, 09 Feb 2018, 04:35

js: allow functions in blocks (ES6)

Unread postby pmuser2 » Mon, 11 Jun 2018, 20:13

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.
Last edited by pmuser2 on Mon, 11 Jun 2018, 20:54, edited 2 times in total.

vannilla
Moonbather
Moonbather
Posts: 62
Joined: Sat, 05 May 2018, 13:29

Re: js: allow functions in blocks (ES6)

Unread postby vannilla » Tue, 12 Jun 2018, 00:57

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.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 21397
Joined: Sun, 28 Aug 2011, 17:27
Location: 58.5°N 15.5°E
Contact:

Re: js: allow functions in blocks (ES6)

Unread postby Moonchild » Tue, 12 Jun 2018, 07:19

Defining functions inside conditionals is really bad practice, you should never do this.
Instead, consider assigning functions to variables:

Code: Select all

var a = function() { /code/ };


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 :)
Improving Mozilla code: You know you're on the right track with code changes when you spend the majority of your time deleting code.

"If you want to build a better world for yourself, you have to be willing to build one for everybody." -- Coyote Osborne

pmuser2
Moongazer
Moongazer
Posts: 9
Joined: Fri, 09 Feb 2018, 04:35

Re: js: allow functions in blocks (ES6)

Unread postby pmuser2 » Tue, 12 Jun 2018, 11:19

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.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 21397
Joined: Sun, 28 Aug 2011, 17:27
Location: 58.5°N 15.5°E
Contact:

Re: js: allow functions in blocks (ES6)

Unread postby Moonchild » Thu, 14 Jun 2018, 09:29

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.
Improving Mozilla code: You know you're on the right track with code changes when you spend the majority of your time deleting code.

"If you want to build a better world for yourself, you have to be willing to build one for everybody." -- Coyote Osborne

pmuser2
Moongazer
Moongazer
Posts: 9
Joined: Fri, 09 Feb 2018, 04:35

Re: js: allow functions in blocks (ES6)

Unread postby pmuser2 » Thu, 14 Jun 2018, 11:59

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.


Return to “Suggestions/feature requests”

Who is online

Users browsing this forum: Moz [Crawler], Yandex [Bot] and 3 guests