This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
David Phillips
Posted Jul 16 - Read on Facebook

Is is possible to use the export/require module convention to externalize classes? I dropped one of my classes into a module file, but adding "export" before "class Foo" throws an error, and without it, I can't access the class.

13 Comments

Jordan Robert Dobson

class exports.MyClass extends Layer

Should work.

David Phillips

that doesn't seem to work for me. "ReferenceError: Can't find variable: MyClass"

Jordan Robert Dobson

Not sure what you're trying to call your class... but here's what mine looks like: http://jrdn.io/byQR

David Phillips

Hmm, maybe I'm doing it wrong on the other end...

do I simply add 'require "file_with_class"' to the top of my main appCode file and then put the file into my 'modules' folder?

Jordan Robert Dobson

I do

{SpriteAnimationLayer} = require "SpriteAnimationLayer"

Jordan Robert Dobson

And yep. Put the file in the modules folder.

David Phillips

That worked. Thanks very much for your help. I'm coming from an Actionscript background so the transition is going to take a bit of time. :)

Jordan Robert Dobson

No problem. Glad you are on your way! :D

David Phillips

Btw, is there a reference for what part of the Coffeescript language the {SpriteAnimationLayer} bit comes from? I like to learn the why's as much as the how's... :)

Jordan Robert Dobson

Honestly I have no fucking clue. I'm curious as well.

Pete Schaffner

David, Framer Studio uses node-style conventions for module requires and thus means you can put individual properties on the 'exports' object (like in Jordan's example ... 'exports.MyClass') or you can assign a value to the whole exported object ('module.exports = class MyClass ...') which will allow you to require like so: 'MyClass = require "module_file"'. The '{MyClass} = ...' syntax is nothing more than a shorthand for referencing a property on the exports object... In other words it is equivalent to 'MyClass = require("module_file").MyClass'. Hope that didn't muddy the waters :\ and let me know if you have any questions

Jordan Robert Dobson

Thanks Pete! Hadn't bothered to look into this. It just worked and I moved on.

David Phillips

Thank you, Pete. That is super helpful!

Read the entire post on Facebook