How to use javaScript classes without constructor in WebStorm with Babel?
This code work in http://jsbin.com (ES6/Babel)
class Human {
gender = 'male';
prnG = ()=> {
console.log(this.gender)
}
}
class Person extends Human {
name = 'Ana';
gender = 'female';
prnN = ()=> {
console.log(this.name);
}
}
const human = new Human();
human.prnG(); //"male"
const person = new Person();
person.prnG(); //"female"
person.prnN(); //"Ana"
I need settings for Babel to trasfer code in classes with constructor and property (this.gender = 'male')
Please sign in to leave a comment.
You need https://babeljs.io/docs/plugins/transform-class-properties/ for this.
- npm i babel-plugin-transform-class-properties babel-preset-env --save-dev
- in .babelrc:
{"plugins": [
"transform-class-properties"
],
"presets": [
"env"
]
}