dudewad
dudewad

Reputation: 13933

Method for using var in Meteor package definition?

For the most part Meteor's documentation is pretty good, but I'm feeling awfully confused on this topic.

When defining your own package, is it true that you can only define variables that you're going to export without using the var keyword?

I.e. lets say I want to define my own new prototype:

SomeProto = function(){}
SomeProto.prototype = {
    //prototype definition...
}

Or, is there a module syntax that I can/should use? Because defining a function like this feels nasty. Real nasty.

I get it, Meteor wraps your package file's definition in an anonymous function, effectively making "private" any variables that are defined using var, and hoisting any that aren't to what presently to me is "Meteor magic land" (still learning this).

But doesn't this seem dirty? Should I be doing something different? I'd really like some kind of export syntax explicitly inside the package file, rather that within the package.js file.

Upvotes: 0

Views: 35

Answers (1)

Stephen Woods
Stephen Woods

Reputation: 4049

Here's a good link to basic package development: https://themeteorchef.com/recipes/writing-a-package/#tmc-writing-package-code

Basically, the magic is happening in api.export(). It definitely feels weird, but if you look at really common packages (aldeed:simple-schema and such), you'll see everyone is doing it.

Upvotes: 0

Related Questions