[英]Ecmascript 6 class in Webstorm 10
I use webstorm 10, and was trying ecmascript 6 with the following code: 我使用webstorm 10,并尝试使用以下代码编写ecmascript 6:
/**
* Class Person
*/
class Person {
/**
* Constructor
* @param lastname
* @param firstname
* @param age
* @param sexe
*/
constructor(lastname, firstname, age, sexe) {
this.lastname = lastname;
this.firstname = firstname;
this.age = age;
this.sexe = sexe;
}
/**
* Return the name as string
* @returns {string}
*/
toString() {
return this.firstname + ' ' + this.lastname;
}
/**
* Return true if is an Adult
* @returns {boolean}
*/
isAdult() {
return this.age > 18;
}
/**
*
* @param {Person} person
* @returns {*}
*/
static isAdult(person) {
return person.isAdult();
}
}
What I am doing wrong that webstorm tell me that firstname and lastname in toString are unresolved variables, so age and as well isAdult() in the static method? webstorm告诉我toString中的firstname和lastname是无法解析的变量,所以age和静态方法中的isAdult()都错了?
I bumped into the same problem. 我遇到了同样的问题。 In order to fix it you have to supply the
@class
annotation. 为了修复它,您必须提供
@class
批注。 This way, it knows it's a class and treats properties as class properties, without warnings. 这样,它知道它是一个类,并且将属性视为类属性,而不会发出警告。
/**
* @class Person
*/
class Person {
...
You might also want to annotate the properties, like so 您可能还想注释属性,就像这样
/**
* @class Person
* @property lastname {String}
* @property firstname {String}
* @property age {Number}
* @property sexe {String}
*/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.