es6-class

*.default is not a constructor, with a imported js plugin

只愿长相守 提交于 2020-01-02 06:43:23
问题 I tried to create a simple form validation and registered this via yarn link in a example project to test the set up. But it absolutely doesn't work and I have no idea how to continue. export default class Proofr { constructor() { console.log('test'); } } This "script" is then generated by webpack , with eslint-loader and babel-loader (presets env & stage-0). So it shouldn't do much more than just for fun logging a message. But in when i try to call new Proofr() it tells me following: form.js

What's the recommended way to customize toString? Using Symbol.toStringTag or overriding toString?

a 夏天 提交于 2019-12-30 03:13:11
问题 I'm confused on what to implement, first, my module will use Babel so there are no problems implementing ES6 features, second, I will use the class construct to create class and not the old prototypal method. So now, I'm confused if I'm going to override toString (which is the old way) or just implement Symbol.toStringTag like what this MDN documentation said, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag So what is the recommended way?

new object in constructor from class undefined

痴心易碎 提交于 2019-12-24 09:18:48
问题 I'm creating a new object from a class in a constructor, and whenever it runs I get an error that operate is undefined in the method, though it is defined in the constructor. Operate itself is thoroughly tested and works great in a separate context so that's not the problem. I'm building it with Babel, not running it directly in Node 7.0.0 import Operate from "./operate" export default class { constructor(Schema) { this.schema = Schema this.operate = new Operate(this.schema) console.log(this

Extending classes and using class attributes in parent class

扶醉桌前 提交于 2019-12-24 05:22:12
问题 I have tried to solve React's annoying bind requirement as follows: class ExtendedComponent extends React.Component { custom_functions: []; constructor(props){ super(props); let self = this; for (let i = 0; i < this.custom_functions.length; i++) { let funcname = this.custom_functions[i]; self[funcname] = self[funcname].bind(self); } } } class OrderMetricsController extends ExtendedComponent { custom_functions: ['refreshTableOnDateChange', 'load', 'refreshTableOnTabChange']; constructor(props)

How to implement “normal” ES5 prototypal inheritance in React?

。_饼干妹妹 提交于 2019-12-24 02:06:20
问题 I am under the impression that ES6 classes are basically a syntactic sugar around the ES5 objects system. As I am trying to run React without a transpiler, I figured that I could use just use the old syntax for defining object "classes" that "inherit" from React.Component. var Board = function(props, state) { var instance = {}; instance.props = props; instance.context = state; return(instance); }; Board.prototype = Object.create(React.Component.prototype); Board.prototype.render = function()

How to implement “normal” ES5 prototypal inheritance in React?

≯℡__Kan透↙ 提交于 2019-12-24 02:06:16
问题 I am under the impression that ES6 classes are basically a syntactic sugar around the ES5 objects system. As I am trying to run React without a transpiler, I figured that I could use just use the old syntax for defining object "classes" that "inherit" from React.Component. var Board = function(props, state) { var instance = {}; instance.props = props; instance.context = state; return(instance); }; Board.prototype = Object.create(React.Component.prototype); Board.prototype.render = function()

Method inside anonymous function inside map is undefined [duplicate]

点点圈 提交于 2019-12-24 02:04:01
问题 This question already has answers here : How do I get the right “this” in an Array.map? (5 answers) Closed 9 months ago . How does one invoke handleButtonPress inside the message map in this example React component? import React, { Component } from 'react'; import {View, Text, TouchableOpacity} from 'react-native'; export default class MyComponent extends Component { constructor(props){ super(props) this.state = {messages:["THANKS", "MERCI", "GRAZIE"]} this.myFunc = this.myFunc.bind(this)

Method inside anonymous function inside map is undefined [duplicate]

寵の児 提交于 2019-12-24 02:03:46
问题 This question already has answers here : How do I get the right “this” in an Array.map? (5 answers) Closed 9 months ago . How does one invoke handleButtonPress inside the message map in this example React component? import React, { Component } from 'react'; import {View, Text, TouchableOpacity} from 'react-native'; export default class MyComponent extends Component { constructor(props){ super(props) this.state = {messages:["THANKS", "MERCI", "GRAZIE"]} this.myFunc = this.myFunc.bind(this)

Merging 2 classes

牧云@^-^@ 提交于 2019-12-23 03:58:31
问题 I want to merge 2 classes or add all methods from 1 class to another. In the future It will be the more classes than just a (ContainerClient) class. Client and ContainerClient I tried this but I think It can be done even easier. for (var a of Object.getOwnPropertyNames(ContainerClient.prototype)) { Client.prototype[a] = ContainerClient.prototype[a]; } Principle: ContainerClient depends on Client Data.js class Data { constructor () { } } Client.js class Client extends Data { me () { return {

Using ES6 Class syntax, how to implement class methods from other files?

半腔热情 提交于 2019-12-22 18:36:33
问题 A class I am writing in NodeJS v8.10 (Webpack built) looks like its about to get really large. I want to break the methods out to their own files, but I also want to maintain the ES6 Class syntax since I come from an OOP background. Is there a nicer ES6 syntax to implement methods of a class from other files? I am presently extending the prototype per the code below, but it would be nice to have everything within the class braces "{}". const fnClose = require('./close'); // about 20 more