On Wed, Mar 21, 2018 at 9:54 PM, Sebastian Malton <[email protected]>
wrote:
>
> ... it is not yanked. Nor is the name exposed. My suggestion is that it
is.

That would be a massively breaking change. Not going to happen. :-)
Consider:

```js
function foo(bar) {
    console.log(typeof bar);
    return function bar() { };
}
foo("");
```

Currently, that logs "string". With your proposal, it would log "function"
just like this code does:

```js
function foo(bar) {
    console.log(typeof bar);
    function bar() { }
    return bar;
}
foo("");
```

...unless the hoisting rules were different for expressions than for
declarations (which would be even more confusing than things already are).

Morever, there's a reason for the existing behavior. You'll have seen code
like this:

```js
function Thing() {
}
Thing.prototype.foo = function foo() { /*...*/ };
Thing.prototype.bar = function bar() { /*...*/ };
```

We don't want those functions in historical code suddenly dumped into the
scope where that code appears, potentially changing its meaning. (JScript
used to do that, but it was fixed in IE9.)

If you want hoisting and an identifier in the scope, use a declaration:

```js
module.exports.fnName2 = fnName;
function fnName (){...}

fnName()
```

(And as Ben Newman points out, with `export` syntax you can export a
function while declaring it by prefixing the declaration with `export`.)

-- T.J. Crowder
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to