Discussion:
Unhoisted class declarations
Isiah Meadows
2014-10-17 00:52:36 UTC
Permalink
I know it was touched on a recent thread
(https://esdiscuss.org/topic/a-new-es6-draft-rev28), but is there a
reason why class declarations aren't hoisted like function
declarations? It is a little confusing to be to type (1) but not (2).

(1)
```js
foo(); // prints "Yay!"

function foo() {
console.log('Yay!');
}
```

(2)
```js
new Foo().speak(); // Error

class Foo {
constructor() {}

speak() {
console.log('Yay!');
}
}
```
--
Isiah Meadows
Domenic Denicola
2014-10-17 00:55:54 UTC
Permalink
https://www.google.com/search?q=class+declarations+hoisted+site%3Aesdiscuss.org leads to https://esdiscuss.org/topic/in-es6-strict-mode-do-function-declarations-within-a-block-hoist as the first result which lays it out pretty clearly.

-----Original Message-----
From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Isiah Meadows
Sent: Thursday, October 16, 2014 20:53
To: es-discuss at mozilla.org
Subject: Unhoisted class declarations

I know it was touched on a recent thread (https://esdiscuss.org/topic/a-new-es6-draft-rev28), but is there a reason why class declarations aren't hoisted like function declarations? It is a little confusing to be to type (1) but not (2).

(1)
```js
foo(); // prints "Yay!"

function foo() {
console.log('Yay!');
}
```

(2)
```js
new Foo().speak(); // Error

class Foo {
constructor() {}

speak() {
console.log('Yay!');
}
}
```

--
Isiah Meadows
Isiah Meadows
2014-10-17 06:54:13 UTC
Permalink
I was more looking for the rationale behind it. I know it currently
doesn't hoist.

On Thu, Oct 16, 2014 at 8:55 PM, Domenic Denicola
Post by Domenic Denicola
https://www.google.com/search?q=class+declarations+hoisted+site%3Aesdiscuss.org leads to https://esdiscuss.org/topic/in-es6-strict-mode-do-function-declarations-within-a-block-hoist as the first result which lays it out pretty clearly.
-----Original Message-----
From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Isiah Meadows
Sent: Thursday, October 16, 2014 20:53
To: es-discuss at mozilla.org
Subject: Unhoisted class declarations
I know it was touched on a recent thread (https://esdiscuss.org/topic/a-new-es6-draft-rev28), but is there a reason why class declarations aren't hoisted like function declarations? It is a little confusing to be to type (1) but not (2).
(1)
```js
foo(); // prints "Yay!"
function foo() {
console.log('Yay!');
}
```
(2)
```js
new Foo().speak(); // Error
class Foo {
constructor() {}
speak() {
console.log('Yay!');
}
}
```
--
Isiah Meadows
_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
--
Isiah Meadows
Claude Pache
2014-10-17 07:52:51 UTC
Permalink
Post by Isiah Meadows
I was more looking for the rationale behind it. I know it currently
doesn't hoist.
In the discussion pointed by Domenic, it is explained why classes don't hoist (namely, in order to avoid premature evaluation of the `extends` clause).
Is something not clear?

?Claude
Post by Isiah Meadows
On Thu, Oct 16, 2014 at 8:55 PM, Domenic Denicola
Post by Domenic Denicola
https://www.google.com/search?q=class+declarations+hoisted+site%3Aesdiscuss.org leads to https://esdiscuss.org/topic/in-es6-strict-mode-do-function-declarations-within-a-block-hoist as the first result which lays it out pretty clearly.
-----Original Message-----
From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Isiah Meadows
Sent: Thursday, October 16, 2014 20:53
To: es-discuss at mozilla.org
Subject: Unhoisted class declarations
I know it was touched on a recent thread (https://esdiscuss.org/topic/a-new-es6-draft-rev28), but is there a reason why class declarations aren't hoisted like function declarations? It is a little confusing to be to type (1) but not (2).
(1)
```js
foo(); // prints "Yay!"
function foo() {
console.log('Yay!');
}
```
(2)
```js
new Foo().speak(); // Error
class Foo {
constructor() {}
speak() {
console.log('Yay!');
}
}
```
--
Isiah Meadows
_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
--
Isiah Meadows
_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141017/d19b0410/attachment.html>
Allen Wirfs-Brock
2014-10-17 16:29:35 UTC
Permalink
Post by Claude Pache
Post by Isiah Meadows
I was more looking for the rationale behind it. I know it currently
doesn't hoist.
In the discussion pointed by Domenic, it is explained why classes don't hoist (namely, in order to avoid premature evaluation of the `extends` clause).
Is something not clear?
and also computed property name expressions

Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141017/c2624b43/attachment.html>
Loading...