Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  125] [ 2]  / answers: 1 / hits: 111143  / 7 Years ago, fri, september 22, 2017, 12:00:00

Why is this example below not outputting hello world? Instead, I am getting:




TypeError: _base2.default.test is not a function




(it is being transpiled with Babel)



file1.js



import Example from './file2';
console.log(Example.test());


file2.js



export default class Example {
test() {
console.log('hello world');
}
}

More From » import

 Answers
9

You are only importing the class, but not making an instance of the class



Try



var myInstance = new Example()
myInstance.test()

[#56418] Tuesday, September 19, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bryantc

Total Points: 455
Total Questions: 96
Total Answers: 110

Location: San Marino
Member since Thu, Jun 30, 2022
2 Years ago
;