static class method or pure functions in node js [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • ES6 modules: Export single class of static methods OR multiple individual methods

    1 answer




due to my learning, I usually use static class methods and OOP more than pure function and functional programming. Some of my work mates dont understand why and I dont know wich way is better. This is a piece of code for example:



const DynamoDbHelper = class DynamoDbHelper {
static getTableProperties(tableName) {
...
}
static async updateTableReadAndWriteCapacities(tableName, readCapacityUnits, writeCapacityUnits) {
...
}
}
module.exports.DynamoDbHelper = DynamoDbHelper;


can also be write:



module.exports.getTableProperties = (tableName) => {
...
}
module.exports.updateTableReadAndWriteCapacities = async(tableName, readCapacityUnits, writeCapacityUnits) => {
...
}


Wich solution is the better in this case?










share|improve this question













marked as duplicate by Bergi node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 8 at 17:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    If both of them work equally well (which they should) it's opinion based
    – UnholySheep
    Nov 8 at 16:49










  • Mostly its just opinion based. I came from a PHP background and as such, share your liking for classes in javascript. But there really is no better way than the other. If you like the grassroots of javascript, use method 2, if you like a little bit of sugar on top, use method 1. Being new to javascript, I tend to cluch to new methods of doing things and opt for option 1
    – Nelson Owalo
    Nov 8 at 17:26










  • Static class methods are not OOP at all.
    – Bergi
    Nov 8 at 17:33















up vote
0
down vote

favorite













This question already has an answer here:




  • ES6 modules: Export single class of static methods OR multiple individual methods

    1 answer




due to my learning, I usually use static class methods and OOP more than pure function and functional programming. Some of my work mates dont understand why and I dont know wich way is better. This is a piece of code for example:



const DynamoDbHelper = class DynamoDbHelper {
static getTableProperties(tableName) {
...
}
static async updateTableReadAndWriteCapacities(tableName, readCapacityUnits, writeCapacityUnits) {
...
}
}
module.exports.DynamoDbHelper = DynamoDbHelper;


can also be write:



module.exports.getTableProperties = (tableName) => {
...
}
module.exports.updateTableReadAndWriteCapacities = async(tableName, readCapacityUnits, writeCapacityUnits) => {
...
}


Wich solution is the better in this case?










share|improve this question













marked as duplicate by Bergi node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 8 at 17:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    If both of them work equally well (which they should) it's opinion based
    – UnholySheep
    Nov 8 at 16:49










  • Mostly its just opinion based. I came from a PHP background and as such, share your liking for classes in javascript. But there really is no better way than the other. If you like the grassroots of javascript, use method 2, if you like a little bit of sugar on top, use method 1. Being new to javascript, I tend to cluch to new methods of doing things and opt for option 1
    – Nelson Owalo
    Nov 8 at 17:26










  • Static class methods are not OOP at all.
    – Bergi
    Nov 8 at 17:33













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • ES6 modules: Export single class of static methods OR multiple individual methods

    1 answer




due to my learning, I usually use static class methods and OOP more than pure function and functional programming. Some of my work mates dont understand why and I dont know wich way is better. This is a piece of code for example:



const DynamoDbHelper = class DynamoDbHelper {
static getTableProperties(tableName) {
...
}
static async updateTableReadAndWriteCapacities(tableName, readCapacityUnits, writeCapacityUnits) {
...
}
}
module.exports.DynamoDbHelper = DynamoDbHelper;


can also be write:



module.exports.getTableProperties = (tableName) => {
...
}
module.exports.updateTableReadAndWriteCapacities = async(tableName, readCapacityUnits, writeCapacityUnits) => {
...
}


Wich solution is the better in this case?










share|improve this question














This question already has an answer here:




  • ES6 modules: Export single class of static methods OR multiple individual methods

    1 answer




due to my learning, I usually use static class methods and OOP more than pure function and functional programming. Some of my work mates dont understand why and I dont know wich way is better. This is a piece of code for example:



const DynamoDbHelper = class DynamoDbHelper {
static getTableProperties(tableName) {
...
}
static async updateTableReadAndWriteCapacities(tableName, readCapacityUnits, writeCapacityUnits) {
...
}
}
module.exports.DynamoDbHelper = DynamoDbHelper;


can also be write:



module.exports.getTableProperties = (tableName) => {
...
}
module.exports.updateTableReadAndWriteCapacities = async(tableName, readCapacityUnits, writeCapacityUnits) => {
...
}


Wich solution is the better in this case?





This question already has an answer here:




  • ES6 modules: Export single class of static methods OR multiple individual methods

    1 answer








node.js oop functional-programming






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 16:46









negstek

158216




158216




marked as duplicate by Bergi node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 8 at 17:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Bergi node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 8 at 17:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    If both of them work equally well (which they should) it's opinion based
    – UnholySheep
    Nov 8 at 16:49










  • Mostly its just opinion based. I came from a PHP background and as such, share your liking for classes in javascript. But there really is no better way than the other. If you like the grassroots of javascript, use method 2, if you like a little bit of sugar on top, use method 1. Being new to javascript, I tend to cluch to new methods of doing things and opt for option 1
    – Nelson Owalo
    Nov 8 at 17:26










  • Static class methods are not OOP at all.
    – Bergi
    Nov 8 at 17:33














  • 2




    If both of them work equally well (which they should) it's opinion based
    – UnholySheep
    Nov 8 at 16:49










  • Mostly its just opinion based. I came from a PHP background and as such, share your liking for classes in javascript. But there really is no better way than the other. If you like the grassroots of javascript, use method 2, if you like a little bit of sugar on top, use method 1. Being new to javascript, I tend to cluch to new methods of doing things and opt for option 1
    – Nelson Owalo
    Nov 8 at 17:26










  • Static class methods are not OOP at all.
    – Bergi
    Nov 8 at 17:33








2




2




If both of them work equally well (which they should) it's opinion based
– UnholySheep
Nov 8 at 16:49




If both of them work equally well (which they should) it's opinion based
– UnholySheep
Nov 8 at 16:49












Mostly its just opinion based. I came from a PHP background and as such, share your liking for classes in javascript. But there really is no better way than the other. If you like the grassroots of javascript, use method 2, if you like a little bit of sugar on top, use method 1. Being new to javascript, I tend to cluch to new methods of doing things and opt for option 1
– Nelson Owalo
Nov 8 at 17:26




Mostly its just opinion based. I came from a PHP background and as such, share your liking for classes in javascript. But there really is no better way than the other. If you like the grassroots of javascript, use method 2, if you like a little bit of sugar on top, use method 1. Being new to javascript, I tend to cluch to new methods of doing things and opt for option 1
– Nelson Owalo
Nov 8 at 17:26












Static class methods are not OOP at all.
– Bergi
Nov 8 at 17:33




Static class methods are not OOP at all.
– Bergi
Nov 8 at 17:33












1 Answer
1






active

oldest

votes

















up vote
1
down vote













Static-only class is antipattern in JavaScript. It's valid only in languages that don't support functions as independent entities.



If a class isn't intended to be instantiated and acts as a namespace, this is what modules are for. The second snippet is how this should be done.






share|improve this answer























  • And any advantage of method 2 over method 1 apart from personal opinion?
    – Nelson Owalo
    Nov 8 at 17:27








  • 1




    @NelsonOwalo It don't create a function (DynamoDbHelper) that will never be used.
    – estus
    Nov 8 at 17:29






  • 1




    TBH I would call it an antipattern in all languages. Those languages that don't support anything outside of class syntax are badly designed imo.
    – Bergi
    Nov 8 at 17:35


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Static-only class is antipattern in JavaScript. It's valid only in languages that don't support functions as independent entities.



If a class isn't intended to be instantiated and acts as a namespace, this is what modules are for. The second snippet is how this should be done.






share|improve this answer























  • And any advantage of method 2 over method 1 apart from personal opinion?
    – Nelson Owalo
    Nov 8 at 17:27








  • 1




    @NelsonOwalo It don't create a function (DynamoDbHelper) that will never be used.
    – estus
    Nov 8 at 17:29






  • 1




    TBH I would call it an antipattern in all languages. Those languages that don't support anything outside of class syntax are badly designed imo.
    – Bergi
    Nov 8 at 17:35















up vote
1
down vote













Static-only class is antipattern in JavaScript. It's valid only in languages that don't support functions as independent entities.



If a class isn't intended to be instantiated and acts as a namespace, this is what modules are for. The second snippet is how this should be done.






share|improve this answer























  • And any advantage of method 2 over method 1 apart from personal opinion?
    – Nelson Owalo
    Nov 8 at 17:27








  • 1




    @NelsonOwalo It don't create a function (DynamoDbHelper) that will never be used.
    – estus
    Nov 8 at 17:29






  • 1




    TBH I would call it an antipattern in all languages. Those languages that don't support anything outside of class syntax are badly designed imo.
    – Bergi
    Nov 8 at 17:35













up vote
1
down vote










up vote
1
down vote









Static-only class is antipattern in JavaScript. It's valid only in languages that don't support functions as independent entities.



If a class isn't intended to be instantiated and acts as a namespace, this is what modules are for. The second snippet is how this should be done.






share|improve this answer














Static-only class is antipattern in JavaScript. It's valid only in languages that don't support functions as independent entities.



If a class isn't intended to be instantiated and acts as a namespace, this is what modules are for. The second snippet is how this should be done.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 8 at 17:32

























answered Nov 8 at 17:23









estus

63.2k2193200




63.2k2193200












  • And any advantage of method 2 over method 1 apart from personal opinion?
    – Nelson Owalo
    Nov 8 at 17:27








  • 1




    @NelsonOwalo It don't create a function (DynamoDbHelper) that will never be used.
    – estus
    Nov 8 at 17:29






  • 1




    TBH I would call it an antipattern in all languages. Those languages that don't support anything outside of class syntax are badly designed imo.
    – Bergi
    Nov 8 at 17:35


















  • And any advantage of method 2 over method 1 apart from personal opinion?
    – Nelson Owalo
    Nov 8 at 17:27








  • 1




    @NelsonOwalo It don't create a function (DynamoDbHelper) that will never be used.
    – estus
    Nov 8 at 17:29






  • 1




    TBH I would call it an antipattern in all languages. Those languages that don't support anything outside of class syntax are badly designed imo.
    – Bergi
    Nov 8 at 17:35
















And any advantage of method 2 over method 1 apart from personal opinion?
– Nelson Owalo
Nov 8 at 17:27






And any advantage of method 2 over method 1 apart from personal opinion?
– Nelson Owalo
Nov 8 at 17:27






1




1




@NelsonOwalo It don't create a function (DynamoDbHelper) that will never be used.
– estus
Nov 8 at 17:29




@NelsonOwalo It don't create a function (DynamoDbHelper) that will never be used.
– estus
Nov 8 at 17:29




1




1




TBH I would call it an antipattern in all languages. Those languages that don't support anything outside of class syntax are badly designed imo.
– Bergi
Nov 8 at 17:35




TBH I would call it an antipattern in all languages. Those languages that don't support anything outside of class syntax are badly designed imo.
– Bergi
Nov 8 at 17:35



Popular posts from this blog

Schultheiß

Liste der Kulturdenkmale in Wilsdruff

Android Play Services Check