es6-class

“await this.method();” doesn’t work in static method

拜拜、爱过 提交于 2021-02-08 13:45:24
问题 I know of the ES6 await feature and I’d like to use it in a function I created in a class. It works well, but when the function is a static function, it doesn’t. Is there any reason for that? Also, what will be the right way to be able to use await inside a static function? class MyClass { resolveAfter2Seconds() { return new Promise(resolve => { setTimeout(() => { resolve('resolved'); }, 2000); }); } static async asyncCall() { console.log('calling'); var result = await this

Is there a way to clear an element from a canvas without eliminating the others?

雨燕双飞 提交于 2021-02-05 11:27:25
问题 I' m building a page loader with canvas, and using the es6 classes... ALthough at the moment I can't make it work properly.. one of the reason is that I can't find a way to clear the canvas in progression. This is my code so far : class Loader { constructor (width, height) { this.width = width this.height = height } _init() { this._createCanvas() this._bindEvents() } // create canvas _createCanvas () { this.canvas = document.createElement("canvas") document.body.appendChild(this.canvas) this

this is not allowed before superclass constructor invocation

巧了我就是萌 提交于 2021-01-29 12:28:16
问题 I want to pass child class instance to super class using super's constructor but I'm get this error super(this); this is not allowed before superclass constructor invocation Why i'm getting this error , also how could I resolve this issue class Parent { constructor(child) { this.child = child; } //...somewhere in code //child.doSomething(); } class Child extends Parent { constructor() { super(this); // <==== the error here } doSomething = () => { //... } } 回答1: There's no need to pass this to

Creating multiple constructor in ES6

拟墨画扇 提交于 2020-12-31 15:16:40
问题 In ES5 it was possible to create multiple constructors for a class while keeping common parts to both using prototypes, as shown below function Book() { //just creates an empty book. } function Book(title, length, author) { this.title = title; this.Length = length; this.author = author; } Book.prototype = { ISBN: "", Length: -1, genre: "", covering: "", author: "", currentPage: 0, title: "", flipTo: function FlipToAPage(pNum) { this.currentPage = pNum; }, turnPageForward: function turnForward

Creating multiple constructor in ES6

谁都会走 提交于 2020-12-31 15:01:57
问题 In ES5 it was possible to create multiple constructors for a class while keeping common parts to both using prototypes, as shown below function Book() { //just creates an empty book. } function Book(title, length, author) { this.title = title; this.Length = length; this.author = author; } Book.prototype = { ISBN: "", Length: -1, genre: "", covering: "", author: "", currentPage: 0, title: "", flipTo: function FlipToAPage(pNum) { this.currentPage = pNum; }, turnPageForward: function turnForward

Creating multiple constructor in ES6

孤人 提交于 2020-12-31 14:57:57
问题 In ES5 it was possible to create multiple constructors for a class while keeping common parts to both using prototypes, as shown below function Book() { //just creates an empty book. } function Book(title, length, author) { this.title = title; this.Length = length; this.author = author; } Book.prototype = { ISBN: "", Length: -1, genre: "", covering: "", author: "", currentPage: 0, title: "", flipTo: function FlipToAPage(pNum) { this.currentPage = pNum; }, turnPageForward: function turnForward

Creating multiple constructor in ES6

≯℡__Kan透↙ 提交于 2020-12-31 14:57:57
问题 In ES5 it was possible to create multiple constructors for a class while keeping common parts to both using prototypes, as shown below function Book() { //just creates an empty book. } function Book(title, length, author) { this.title = title; this.Length = length; this.author = author; } Book.prototype = { ISBN: "", Length: -1, genre: "", covering: "", author: "", currentPage: 0, title: "", flipTo: function FlipToAPage(pNum) { this.currentPage = pNum; }, turnPageForward: function turnForward

Creating multiple constructor in ES6

只愿长相守 提交于 2020-12-31 14:57:48
问题 In ES5 it was possible to create multiple constructors for a class while keeping common parts to both using prototypes, as shown below function Book() { //just creates an empty book. } function Book(title, length, author) { this.title = title; this.Length = length; this.author = author; } Book.prototype = { ISBN: "", Length: -1, genre: "", covering: "", author: "", currentPage: 0, title: "", flipTo: function FlipToAPage(pNum) { this.currentPage = pNum; }, turnPageForward: function turnForward

why do functional component in reactjs not have instances?

巧了我就是萌 提交于 2020-12-29 10:46:51
问题 In React quickstart, it is stated about Refs and Functional Components that You may not use the ref attribute on functional components because they don't have instances: function MyFunctionalComponent() { return <input />; } class Parent extends React.Component { render() { // This will *not* work! return ( <MyFunctionalComponent ref={(input) => { this.textInput = input; }} /> ); } } I don't fully understand the above statement and the example. So far from reading the tutorials, the only

why do functional component in reactjs not have instances?

做~自己de王妃 提交于 2020-12-29 10:44:23
问题 In React quickstart, it is stated about Refs and Functional Components that You may not use the ref attribute on functional components because they don't have instances: function MyFunctionalComponent() { return <input />; } class Parent extends React.Component { render() { // This will *not* work! return ( <MyFunctionalComponent ref={(input) => { this.textInput = input; }} /> ); } } I don't fully understand the above statement and the example. So far from reading the tutorials, the only