Difference between export as class and object in javascript ?

// ExampleClass.jsexport default class ExampleClass {
constructor() {
if (this.constructor.instance) {
return this.constructor.instance;
}
this.constructor.instance = this;
}
/**
* @name ExampleClass#setData
* Role of this function is to set data
* @param {Object} data
*/
setData(data) {
this.data = data;
}
/**
* @name ExampleClass#getData
* Role of this function is to get data
* @returns {Object} data
*/
getData() {
return this.data;
}
}

How to avoid this ?

const example = {
data: {},
};
export default {
setData(token, isIVToken = false) {
example.data = {
key: 'value'
}
},
getData() {
return example.data
},
};

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Avinash Dalvi

Avinash Dalvi

115 Followers

Enthusiastic learner, Full Stack Developer, Techno Savvy, Traveller, Out of Box thinker, Agile Lover, Problem Solver, Blogger