Re: Re: Async Class

2019-08-27 Thread Dimitrian Nine
 Claude Pache
> class consists not only of its constructor
How i see it - seems all think that my idea not bad, but we have semantic
hell.
My thougth was Class is wrapper for constructor object
And Async Class is same wrapper for constructor Promise of object

kai zhu
>class-factories are good enough

For all? Not for me - i want more clean and native methods.
> if the below Browser/Page classes were also "async"

And way you described - try to Extends Browser Class. How you do that?
I think my wrapper more easy and simple.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Async Class

2019-08-27 Thread kai zhu
class-factories are good enough. as real-world example, google-puppeteer
uses class-factories to promisify its constructors, which are
easy-to-reason.

if the below Browser/Page classes were also "async", it would be difficult
to
debug their intent in real-world code -- are their instances supposed to act
as promises or as data-objects? i imagine code-maintennance would be a
nightmare.



```js
// "await" puppeteer's Browser constructor
// https://github.com/GoogleChrome/puppeteer/blob/v1.19.0/lib/Browser.js#L23
class Browser extends EventEmitter {
constructor(connection, contextIds, ...) {
...
}
static async create(connection, contextIds, ...) {
const browser = new Browser(connection, contextIds, ...);
await connection.send(...);
return browser;
}
}
//
https://github.com/GoogleChrome/puppeteer/blob/v1.19.0/lib/Launcher.js#L184
const browser = await Browser.create(connection, [], ...);



// "await" puppeteer's Page constructor
// https://github.com/GoogleChrome/puppeteer/blob/v1.19.0/lib/Page.js#L36
class Page extends EventEmitter {
constructor(client, target, ...) {
...
}
static async create(client, target, ...) {
const page = new Page(client, target, ...);
await page._initialize();
...
return page;
}
}
//
https://github.com/kaizhu256/puppeteer-to-istanbul-example/blob/6b3f599f/screenshot.js#L317
page1 = await module.exports.Page.create(null, tmp);
```




On Tue, Aug 27, 2019 at 11:36 AM Claude Pache 
wrote:

>
>
> Le 26 août 2019 à 17:11, Dimitrian Nine  a
> écrit :
>
> Class is just function constructor that return object
>
>
> Although in JS a class is represented by the same object as its
> constructor, I don’t think it is good to assimilate the concept of JS class
> and JS constructor. Indeed, a class consists not only of its constructor,
> but also of all its associated methods. This is what is suggested by the
> syntax:
>
> ```js
> class C {
> /* definition of all methods, not only constructor */
> }
> ```
>
> From that perspective, I understand very well what would be an “async
> constructor”; but an “async class” doesn’t make much sense.
>
> —Claude
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Async Class

2019-08-27 Thread Claude Pache


> Le 26 août 2019 à 17:11, Dimitrian Nine  a écrit :
> 
> Class is just function constructor that return object

Although in JS a class is represented by the same object as its constructor, I 
don’t think it is good to assimilate the concept of JS class and JS 
constructor. Indeed, a class consists not only of its constructor, but also of 
all its associated methods. This is what is suggested by the syntax:

```js
class C { 
/* definition of all methods, not only constructor */ 
}
```

From that perspective, I understand very well what would be an “async 
constructor”; but an “async class” doesn’t make much sense.

—Claude___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss