0

I am getting up to speed on ES6 classes loaded with JSPM.

For example:

export class Alerter{
    doAlert(message)
    {
        alert(message);
    }
}

Then I import this above another class:

import Alerter from 'services/alerter';

Then I use the class:

var alerter = new Alerter();

This line throws an error: object does not support his method.

Is there a different way I should be writing this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Greg Gum
  • 33,478
  • 39
  • 162
  • 233
  • I'm curious, what browser are you using? I'm pretty sure my answer below is the issue, but that error message isn't one I'm familiar with. – loganfsmyth Jul 15 '15 at 21:44

1 Answers1

0

You are exporting a named export and importing the default export. You either need to do

export default class Alerter {

so that you have an export to import, or

import {Alerter} from 'services/alerter';

so that you import the correct constructor.

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
  • Thank you, both of those work. (The browser I am testing with is IE 11. In Chrome, the error was "undefined is not a function") – Greg Gum Jul 16 '15 at 11:59