admin管理员组文章数量:1305134
I just moved from android to React Native recently. So need some help. Why I not able to access the variable on same class, for example when I call URL_API_SERVER from another class, it give me 'Undefined/api/v2'.
class Constant {
static BASE_URL = 'https://xxxxx';
static URL_API_SERVER = this.BASE_URL + '/api/v2';
static STATIC_BASEURL = this.BASE_URL + '/static';
static URLSTRING_FAQ = this.STATIC_BASEURL + '/FAQ.html';
static URLSTRING_TOU = this.STATIC_BASEURL + '/TOU.html';
}
export default Constant;
I just moved from android to React Native recently. So need some help. Why I not able to access the variable on same class, for example when I call URL_API_SERVER from another class, it give me 'Undefined/api/v2'.
class Constant {
static BASE_URL = 'https://xxxxx';
static URL_API_SERVER = this.BASE_URL + '/api/v2';
static STATIC_BASEURL = this.BASE_URL + '/static';
static URLSTRING_FAQ = this.STATIC_BASEURL + '/FAQ.html';
static URLSTRING_TOU = this.STATIC_BASEURL + '/TOU.html';
}
export default Constant;
Share
Improve this question
asked Nov 7, 2016 at 8:29
Newbie009Newbie009
2952 silver badges13 bronze badges
1 Answer
Reset to default 8Since you are using static
variable, you cannot use this
. You can access the static variable like below.
class Constant {
static BASE_URL = 'https://xxxxx';
static URL_API_SERVER = Constant.BASE_URL + '/api/v2';
static STATIC_BASEURL = Constant.BASE_URL + '/static';
static URLSTRING_FAQ = Constant.STATIC_BASEURL + '/FAQ.html';
static URLSTRING_TOU = Constant.STATIC_BASEURL + '/TOU.html';
}
export default Constant;
本文标签: javascriptReact NativeAccessing static variable on same classStack Overflow
版权声明:本文标题:javascript - React Native - Accessing static variable on same class - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741798290a2398068.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论