admin管理员组文章数量:1425161
I am creating a node package to handle cookies. What is the best way to export static class methods from the class below?
export default class Cookies {
static get (name) {...}
static set (...) {...}
static remove (...) {...}
}
And is it then possible to import them like this, so people don't have to import the remove method if they don't need it?
import { get, set } from "Cookies"
I am creating a node package to handle cookies. What is the best way to export static class methods from the class below?
export default class Cookies {
static get (name) {...}
static set (...) {...}
static remove (...) {...}
}
And is it then possible to import them like this, so people don't have to import the remove method if they don't need it?
import { get, set } from "Cookies"
1 Answer
Reset to default 6Since they are static methods, they are basically just properties on the class object. Since that is the case, you can just export them one by one:
export default class Cookies {
static get (name) {...}
static set (...) {...}
static remove (...) {...}
}
export const get = Cookies.get;
export const set = Cookies.set;
export const remove = Cookies.remove;
本文标签: javascriptHow can I export static class methods without exporting the whole classStack Overflow
版权声明:本文标题:javascript - How can I export static class methods without exporting the whole class - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745404190a2657175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论