Async Class
Isiah Meadows
isiahmeadows at gmail.com
Mon Feb 19 17:02:32 UTC 2018
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) {
const img = await load(path)
await filter1(img)
await filter2(img)
return img
}
// ext-filter-img.js
import * as FilterImg from "./filter-img.js"
async function create(path) {
const img = await FilterImg.create(path)
await extFilter1(img)
await extFilter2(img)
return img
}
(async () => {
let ExtFilterImg = await import("./ext-filter-img.js")
let extFilterImg = await ExtFilterImg.create(path)
// ...
})()
```
[1]: https://github.com/isiahmeadows/thallium/blob/master/lib/cli/loader.js
-----
Isiah Meadows
me at isiahmeadows.com
Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com
On Mon, Feb 19, 2018 at 2:49 AM, Dimitrian Nine
<dimtimeforever at gmail.com> wrote:
> "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 - try create:
> ```js
> //some module
> async class FilterImg{
> constructor(path,filters){
> this.img = await load(path);
> if (filters) {await this.use_filters(filters);}
> }}
> async use_filters(filters){
> await filter1(this.image);
> await filter2(this.image);
> }}//class
> export default FilterImg;
> //end module
>
> void async finction(){
> let FilterImg = (await import(url)).default;
> async class ExtFilterImg extends FilterImg{
> constructor(path,filters){
> await super(path);
> if (filters) {await this.use_extFilters(filters);}
> }}//class
>
> let extFilter_img = await new FilterImg(path,filters);
> console.log(extFilter_img.src+' '+extFilter_img.filters);
> }();
> ```
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
More information about the es-discuss
mailing list