Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fds:coffeescript-share

Exports Meteor's CoffeeScript __coffeescriptShare object so that you can 'use strict' in your CoffeeScript files.

Warning

fds:coffeescript-share is only for use with Meteor applications and is not for use by other packages.

fds:coffeescript-share makes the same share object available to everything that uses it. This allows shared objects to leak outside of their package. This is only a problem when fds:coffeescript-share is used by other packages.

Install

$ meteor add fds:coffeescript-share

Background

Meteor allows CoffeeScript users to share objects between files without polluting the global namespace by creating properties on a special object, share, e.g.;

1_first.coffee

share.greet = (name) ->
  console.log "Hello, #{ name }!"

2_second.coffee

share.greet 'World'

This works because when Meteor compiles a CoffeeScript file, it prepends;

__coffeescriptShare = typeof __coffeescriptShare === 'object' ?
    __coffeescriptShare : {};
var share = __coffeescriptShare;

These statements ensure the global __coffeescriptShare exists and assigns it to a file-scope variable share.

However, strict mode wont let you create a global like this. Instead, a ReferenceError is thrown (try adding 'use strict' to the example above).

This package safely creates and exports __coffeescriptShare so that you can 'use strict' in your CoffeeScript files.

Example

To run the example;

$ cd example
$ meteor

Open a browser and navigate to http://localhost:3000 and check that Hello, World! appears on the console. Then remove fds:coffeescipt-share and watch it explode;

$ meteor remove fds:coffeescript-share

Then remove the 'use strict' and see it work again (but in lax mode*).

*I just made that name up.

About

Exports Meteor's CoffeeScript __coffescriptShare object so you can 'use strict' in your CoffeeScript files

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages