Can't get custom class loaded

Hello,

I cannot load a file containing a class which extend another class defined in another file. I tried putting it together in lib directory as i would like to use them in the project but even if the name of the second alphabetically after. It doesn’t work. Then i tried to just put the second out of the lib folder but still when it comes to load the second class, it can’t access the first.

2 classes like :

HfrObject.js :

class HfrObject {
	constructor(item) {
		...
	}
}

HfrMyCustom.js :

class HfrMyCustom extends  HfrObject {
	constructor(item) {
		...
	}
}

And HfrMyCustom is used in my react components.

the error is :

W20160303-13:53:48.134(1)? (STDERR) ReferenceError: HfrObject is not defined
W20160303-13:53:48.134(1)? (STDERR)     at modules/Custom/lib/HfrMyCustom.js:1:28

Where should i put those files please?

If you’re on 1.3, use import/export. If not, you have to declare your class as a global variable. Like so:
HfrObject = class HfrObject {}

If you’re still getting the error after that, it might be a load order issue. Which will also be easily resolved by upgrading to 1.3 and using import/export. But, if you don’t want to go with 1.3 (yet), you have to follow the load order rules. They’re specified in the docs if I’m not mistaken.

2 Likes

You’re running into file scope issues, where the class is locally scoped. You could do HfrObject = class HfrObject {... to define a globally scoped reference, or use modules by updating to the 1.3 beta release.

@maartenbusstra : snap :smile:

1 Like

Teehee :smiley:

@blemoine the load order stuff is here: http://docs.meteor.com/#/full/fileloadorder

1 Like

Thank you very much, indeed i am on 1.2. The globals fixed it. Ill take a look to that link.