Why method is not defined?

What am I doing wrong? get the indexPage.addScripts is not a function
class Page {
 constructor({ pageName, scriptNames, styleNames }) {
 if (!pageName || typeof pageName != "string") {
 throw new Error("Enter page name in config file!!!");
}

 this.name = pageName;
 this.scripts = scriptNames || [];
 this.styles = styleNames || [];

 return this.data();
}

 addScripts(scripts) {
 if (Array.isArray(scripts)) {
 this.scripts = this.scripts.concat(scripts);
 } else {
this.scripts.push(scripts.toString());
}
}

 addStyles(styles) {
 if (Array.isArray(styles)) {
 this.styles = this.styles.concat(styles);
 } else {
this.styles.push(styles.toString());
}
}

 data() {
 return {
 name: this.name
 scripts: this.scripts
 styles: this.styles
};
}
}

let indexPage = new Page({
 pageName: 'index',
 scriptNames: [
'index',
'main'
],
 styleNames: [
'frontpage'
]
});

indexPage.addScripts('geo');
March 23rd 20 at 19:31
1 answer
March 23rd 20 at 19:33
Solution
Substituting a class instance to another object. Here it is from the constructor should be removed:

return this.data();
thank you - Adelle.Legros commented on March 23rd 20 at 19:36

Find more questions by tags JavaScript