mbigras mbigras - 1 month ago 9
CoffeeScript Question

Where does the coffeescript underline method come from?

I've been digging around in the atom/apm code looking the where the function definition, or package dependency is. It gets called in

src/view.coffee
on line 93

items.push(repository.underline)
items.push(pack.description.replace(/\s+/g, ' ')) if pack.description


But I'm not sure where that method comes from, or how I would be able to reproduce it in the node REPL. Where does it come from?

Answer

repository.underline is not a method (no parentheses), it's a property of the repository variable.

The repository variable comes from pack.repository.url or pack.repository.

pack is populated from a JSON HTTP API response. repository is in the metadata which comes from the JSON in versions[version]. version is decided by getLatestCompatibleVersion.

Taking a sample response for the minimap package it appears all the repository values for specific versions are plain strings, so the .underline property doesn't come from an object there. As they are plain strings something has probably extended the javascript String prototype to include an underline property, but what?

From your sample search it looks like .underline is used for terminal type output. Looking at the package.json dependencies, the colors package works in that space.

colors adds a number of properties to the string prototype, including underline.

This is a good example of why extending prototypes can get confusing.