javascript - How can I export static class methods without exporting the whole class - Stack Overflow

I am creating a node package to handle cookies. What is the best way to export static class methods fro

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"

Share Improve this question asked Sep 23, 2016 at 13:59 Stefan VerweijStefan Verweij 551 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Since 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;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745404191a4626239.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信