Update: [now we have proposal 1 stage][1]
[1]: https://github.com/bmeck/proposal-async-init/issues/1
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
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
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
> 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
How it says: "there is no limit to perfection" - [new wrapper][1]. Now it
works like more native:
```js
class PromiseClass {
static async new(test='test'){ this.promise= test; return this;}
constructor(...args) {
let s = async()=>PromiseClass.new.call(this,...args);
return (async r=>await s()
>Not a bad idea, but I'd strongly prefer the promise to be returned from
new >AsyncClass(...) itself instead
This about wrapper? He is just example of how functional can work right now.
>I do have a preference: async should decorate the constructor, not the
class
How i say before: both variants
Not a bad idea, but I'd *strongly* prefer the promise to be returned
from `new AsyncClass(...)` itself instead. And down that vein, `super`
with async classes should also implicitly `await` in its `super` call,
setting `this` to the value itself. For sanity reasons, `super` should
return a promise
Ok so much time has passed. I have learned more js. And created some
[wrapper][1] for my idea:
Class is just function constructor that return object
Async Class is async function constructor that returns promise object.
Wrapper code:
```js
class PromiseClass { //promisified class
static async
([Classes][1]):
[1]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
«JavaScript classes, introduced in ECMAScript 2015, are primarily
syntactical sugar over JavaScript's existing prototype-based inheritance.
The class syntax does not introduce a new object-oriented
```js
class Test{
constructor(){}
async init(){}
static async newA(){
let obj = new Test(); obj.init(); return obj
}}
let t = Test.newA();
class ExtTest extends Test(){
constructor(){
super(); // we cant init here
//now we must recreate new/init for ExtTest too
}}
```
Or with my proposal we can
"why a static factory"
And more notes:
"return img" - this is cut version
In my example you get obj - not image.
And my sample was simple.
I hope not so long left to class private var + decorators
And sample can be then more complex with it:
async class Class{
@some_decorator
static private
"ES classes are about 90% sugar"
"ES classes aren't like traditional classes"
Yes and i just want to more sugar for them - just simple.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
I just thought I'd politely point out here that JS isn't a purely OO
language (it's even less so class-based OO - ES classes are about 90%
sugar over prototype-based inheritance\*). Also, C#, the language that
*first* had this kind of syntax, [also doesn't have this][1].
Constructors should be
"why a static factory"
I answered earlier:
<>
Yes, you can, but for me more easy to work with classes.
And i just want to extend the functionality for work with async - that all.
___
I'm still struggling through this thread to see why a static factory
method/function with a private constructor/class doesn't suffice for
this, or in this case, just procedural functions? (That's what I
normally do, [even in ES5][1].)
```js
// filter-img.js
export async function create(path) {
"I think awaitNew MyObject() would fit the thrust of your idea more"
For me more good my first version... async class = return Promise(obj)
But i can agree with others decisions, if in the end i get: easy way to
async new
Some people ask me for some more interesting sample...
Maybe it can help
I think `awaitNew MyObject()` would fit the thrust of your idea more. This
would allow `new MyObject()` to still be an instance of the object instead
of a promise, even if the constructor is async. It would dispatch the async
parts of the constructor to the background instead of awaiting it. e.g.:
"Long story short, introducing this feature would slow down new/
Reflect.construct"
"since this might suggest it returning a Promise, which it mustn't "
Can it help: if async class constructor will be return Promise(obj) and i
suggest before use newAsync for that practice?
Slow... but how much?
Having the constructor return a `Promise` is generally considered bad
practice, since it breaks `new X instanceof X`, which in general breaks
inheritance.
So, for this idea to work, you really shouldn't mark `constructor` as `async`
(since this might suggest it returning a `Promise`, which it
On Sun, Feb 18, 2018 at 9:07 AM, Naveen Chawla
wrote:
>
> There is no rule that says you must propagate every promise.
I never said there was. I said you must handle rejection, or propagate the
promise. Or, yes, you can ensure that the promise is never rejected, but
that's
"new MyObject() would return a promise "
I have one idea about it, but not sure good or not...
async class and then newAsync
Maybe this way more good for someone...
___
es-discuss mailing list
es-discuss@mozilla.org
In the example, promise rejection can be handled with a try+catch inside
`initializeAsync()` itself. But we're deviating from the topic of "async
constructor", from which this is separate
On Sun, 18 Feb 2018, 2:37 pm Naveen Chawla, wrote:
> There is no rule that says you
There is no rule that says you must propagate every promise.
`initializeAsync` doesn't return anything, so the constructor just kicks
off the async process.
On Sun, 18 Feb 2018, 2:02 pm T.J. Crowder,
wrote:
> On Sun, Feb 18, 2018 at 8:27 AM, Naveen Chawla
On Sun, Feb 18, 2018 at 8:27 AM, Naveen Chawla
wrote:
>
> Like this:
>
> ```js
> class MyObject{
> constructor(){
> initializeAsync();
> }
>
> async initializeAsync(){
> await doSomething();
> await doSomethingElse();
> //etc.
>
Like this:
```js
class MyObject{
constructor(){
initializeAsync();
}
async initializeAsync(){
await doSomething();
await doSomethingElse();
//etc.
}
}
```
Of course if you wanted to await at the constructor call level (and await
inside the
"You can just call an async method from the constructor (without await) -
and then let that async method handle all the asynchronicity."
Not sure about it - how control? callback?
I prefer async/await then.
"I think async constructor would make more sense than async class"
Maybe: i use it for
You can just call an async method from the constructor (without await) -
and then let that async method handle all the asynchronicity.
Does this satisfy your use case?
I think `async constructor` would make more sense than `async class`.
Calling `new MyObjectAsync()` would have to return a
"It gets ugly(ier) when you want to extend that. :-) "
Ok, i get it, but yes i prefer some more sugar like as i suggested before.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
> I think he means literally returning a promise.
That would be the correct assumption. ;-)
-
Isiah Meadows
m...@isiahmeadows.com
Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com
On Fri, Feb 16, 2018 at 3:05 AM, T.J. Crowder
On Fri, Feb 16, 2018 at 7:51 AM, Dimitrian Nine
wrote:
>
> "Also, note that you can return promises out of the constructor (and I've
done it before)"
>
> Like callback?
I think he means literally returning a promise. If you return an object out
of the constructor, that
"Is an async factory function/method not sufficient to do this?"
Maybe, but i think it question similiar to "factory vs class":
we can use Сlass now, but why not to extend it to Async then?
"Also, note that you can return promises out of the constructor (and I've
done it before)"
Like callback?
Is an async factory function/method not sufficient to do this? Also,
note that you *can* return promises out of the constructor (and I've
done it before).
-
Isiah Meadows
m...@isiahmeadows.com
Looking for web consulting? Or a new website?
Send me an email and we can get started.
32 matches
Mail list logo