Typescript : underscore convention for members [closed]

Those who say, must not use the “_”, for them, here is some code from TypeScript site: class Employee { private _fullName: string; get fullName(): string { return this._fullName; } this._fullName = …… } Same question on Stackoverflow, you should have a look on it, especially the answer. For the time being, if accepted, we … Read more

Why Jest’s toThrow won’t work when create an instance of a ES6 class directly in the constructor?

Here expect(new TestObject()).toThrow(); new TestObject() is evaluated first, then expect(…), then …toThrow(), in accordance with operator precedence. When new TestObject() throws, anything else doesn’t matter. This is why toThrow expects a function that is supposed to throw: expect(() => { new TestObject(); }).toThrow(); This way it can be wrapped with try..catch internally when being called. … Read more

How do you check the difference between an ECMAScript 6 class and function?

I think the simplest way to check if the function is ES6 class is to check the result of .toString() method. According to the es2015 spec: The string representation must have the syntax of a FunctionDeclaration FunctionExpression, GeneratorDeclaration, GeneratorExpression, ClassDeclaration, ClassExpression, ArrowFunction, MethodDefinition, or GeneratorMethod depending upon the actual characteristics of the object So the … Read more

How do I use a static variable in ES6 class?

Your class has no static variables (if by static variable you mean static property). getCount returns NaN (after you call increaseCount) because Animal has no count property initially. Then increaseCount does undefined + 1 which is NaN. Instances created by new Animal have a count property initially, but Animal itself does not until you call … Read more

Serializing an ES6 class object as JSON

As with any other object you want to stringify in JS, you can use JSON.stringify: JSON.stringify(yourObject); class MyClass { constructor() { this.foo = 3 } } var myClass = new MyClass() console.log(JSON.stringify(myClass)); Also worth noting is that you can customize how stringify serializes your object by giving it a toJSON method. The value used to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)