【问题标题】:Where does the coffeescript underline method come from?咖啡脚本下划线方法从何而来?
【发布时间】:2016-10-31 15:51:13
【问题描述】:

我一直在atom/apm code 中寻找函数定义或包依赖项的位置。它在第 93 行的src/view.coffee 中调用

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

但我不确定该方法来自哪里,或者我如何能够在节点 REPL 中重现它。它来自哪里?

【问题讨论】:

    标签: node.js coffeescript


    【解决方案1】:

    repository.underline 不是方法(没有括号),它是repository 变量的属性。

    repository variable 来自pack.repository.url or pack.repository

    pack is populated from a JSON HTTP API responserepositorymetadata 中,它来自 versions[version] 中的 JSON。 versiongetLatestCompatibleVersion 决定。

    采用sample response for the minimap package 时,特定版本的所有repository 值似乎都是纯字符串,因此.underline 属性不是来自那里的对象。由于它们是纯字符串,因此某些东西可能已经扩展了 javascript String 原型以包含underline 属性,但是什么?

    从您的sample search 看来,.underline 用于终端类型输出。看着package.json dependencies, the colors package works in that space

    colorsadds a number of properties to the string prototype,包括underline

    这是一个很好的例子,说明了为什么扩展原型会令人困惑。

    【讨论】: