Tuesday, June 19, 2012

CoffeeScript, Uglifier, and constructor.name

The past six month's I've become a CoffeeScript convert.  For the most part adopting CoffeeScript has been an easier one than I anticipated.  Pushing my first app to production today, I found an interesting bug that I thought I'd document here in case others are searching for a solution.

If you're using uglifier in addition to CoffeeScript, be careful about also using constructor.name.  Constructor.name is a useful way to determine the name of the class that called a function in the case where you are using inheritance.  However constructor.name's response will change if you're using uglifier and it goes and shortens the name of the calling class/function.  The solution - don't use uglifier or use the --no-mangle option.

Keywords: coffeescript, rails, uglifier, this.constructor.name, heroku

No comments: