Coffeescript 什么';这行咖啡剧本的意思是什么?

Coffeescript 什么';这行咖啡剧本的意思是什么?,coffeescript,Coffeescript,我正在读《记者》杂志,无意中发现了这一行代码: markdown = _.template(source.toString()) variables Journo.render = (post, source) -> catchErrors -> do loadLayout source or= fs.readFileSync postPath post variables = renderVariables post

我正在读《记者》杂志,无意中发现了这一行代码:

markdown  = _.template(source.toString()) variables
Journo.render = (post, source) ->
      catchErrors ->
        do loadLayout
        source or= fs.readFileSync postPath post
        variables = renderVariables post
        markdown  = _.template(source.toString()) variables
        title     = detectTitle markdown
        content   = marked.parser marked.lexer markdown
        shared.layout _.extend variables, {title, content}
变量
在这里做什么?
\u.template(source.toString())变量是否有效

下面是包装这行代码的函数:

markdown  = _.template(source.toString()) variables
Journo.render = (post, source) ->
      catchErrors ->
        do loadLayout
        source or= fs.readFileSync postPath post
        variables = renderVariables post
        markdown  = _.template(source.toString()) variables
        title     = detectTitle markdown
        content   = marked.parser marked.lexer markdown
        shared.layout _.extend variables, {title, content}

是的,它是有效的。调用函数时,CoffeeScript中的括号是可选的(有时),因此它会获取
template
的结果并使用参数调用它。它编译为以下JavaScript:

_.template(source.toString())(variables);
从咖啡脚本:

如果传递参数,则不需要使用括号来调用函数。隐式调用向前换行到行或块表达式的末尾


是的,它是有效的。调用函数时,CoffeeScript中的括号是可选的(有时),因此它会获取
template
的结果并使用参数调用它。它编译为以下JavaScript:

_.template(source.toString())(variables);
从咖啡脚本:

如果传递参数,则不需要使用括号来调用函数。隐式调用向前换行到行或块表达式的末尾


\uU9.template
编译由
source.toString()
指定的模板。模板是一个函数,然后调用它
variables
是该函数的参数(就像
postPath post
fs.readFileSync
的参数一样)


另请参见
的文档。template
编译由
源.toString()指定的模板。模板是一个函数,然后调用它
variables
是该函数的参数(就像
postPath post
fs.readFileSync
的参数一样)


另请参阅文档,以了解

这个问题得到了很好的回答,但为了帮助OP在未来的咖啡特技中发挥作用,一个很好的方法是

  • 转到coffeescript.org网站
  • 点击“试试咖啡脚本”
  • 将拼图剪切/粘贴到coffeescript部分
  • 宾果!您可以看到生成的javascript

  • 我承认有时会对咖啡脚本感到困惑,这是abs fab。。这个问题得到了很好的回答,但是为了帮助OP在未来的咖啡特技表演中发挥作用,一个很好的方法就是

  • 转到coffeescript.org网站
  • 点击“试试咖啡脚本”
  • 将拼图剪切/粘贴到coffeescript部分
  • 宾果!您可以看到生成的javascript

  • 我承认有时会对咖啡脚本感到困惑,这是abs fab。。而且省去了麻烦。

    您可能应该添加下划线的
    模板(源、对象)
    函数curries;如果不提供对象,则返回一个函数,该函数接受对象并生成模板化结果。您可能应该添加下划线的
    模板(源,对象)
    函数curries;如果不提供对象,则返回一个函数,该函数接受对象并生成模板化结果。