javascript - ES6 export extended class and then import it -


i have basic class (mobile.js)

class mobile {     constructor() {         ...     }     method(msg){        ...     } } module.exports = mobile; 

then import (mobileextended.js);

import mobile './mobile';   class mobilephone extends mobile {      method(){         super.method('hello world!');      }    } module.exports = mobilephone; 

and in end want import mobilephone.js:

 import mobilephone './mobileextended.js';      mobilephone.method(); 

how can make work in es6 style? because i'm getting cannot read property 'open' of undefined error.

if want name things in palce import them, such as

import mobile './mobile' 

you should use default export, such as

export default mobile 

from place mobile defined.


compare having named export

export class mobile { ... } 

and importing specific name in separate module.

import {mobile} mobile 

however, pointed out loganfsmyth in comments, not source of error. use non-static method, need create instance of class.

const mobilephone = new mobilephone() mobilephone.method() 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -