I'm playing around with some ES6 features and I'm trying to convert some of my old code's class structure to an ES6 class equivalent.
var App = function() {
/**
* Public method calling a private method.
*/
this.init = function() {
events();
};
/**
* Private method.
*/
var handleClickEvent = function() {
console.log('Click handled');
};
/**
* Private method with event calling private
* method in this class.
*/
var events = function() {
document.addEventListener('click', handleClickEvent);
};
};
(new App).init();
Is this the correct approach by making the methods static
or is there a private
equivalent, also can static methods be called form outside the class like App.events()
?
class App {
constructor() {
App.events();
}
static handleClickEvent() {
console.log('Click handled');
}
static events() {
document.addEventListener('click', App.handleClickEvent);
}
}
new App();