Function declaration in labelled statements

Shijun He hax.sfo at gmail.com
Tue Aug 28 05:51:20 PDT 2012


ES5 strict mode disallow Function declaration in any statements. It's
fine, but Function declaration in top labelled statements seems
harmless, why not relax the rules to allow them so we can use "Labeled
Modules Specification" ? Though it seems too late to fix.

Code example:

'use strict' // cause SyntaxError: In strict mode code, functions can
only be declared at top level or immediately within another function.

exports: function area(x1, y1, x2, y2){
  return length(x1, x2) * length(y1, y2);
}


References:
Labeled Modules Specification:
https://github.com/labeledmodules/labeled-modules-spec
LMS implementation: https://npmjs.org/package/linkjs
my.js (ES6-like module system which utilize the same ideas from LMS
for import/export syntax): http://github.com/hax/my.js

--
hax


More information about the es-discuss mailing list