简体   繁体   English

尝试将js函数更改为coffeescript时出现Uncaught ReferenceError

[英]Uncaught ReferenceError when trying to change js function into coffeescript

This is the error: 这是错误:

Uncaught ReferenceError: er is not defined

This is the code .. 这是代码..

{CompositeDisposable} = require 'atom'
lib = require 'lib'

module.exports =
  subscriptions: null

  activate: ->
    @subscriptions = new CompositeDisposable
    @subscriptions.add atom.commands.add 'atom-workspace',
      'my-package:convert': => @convert()

  deactivate: ->
    @subscriptions.dispose()

  convert: ->
    console.log 'Convert text!'
    if editor = atom.workspace.getActiveTextEditor()
      console.log editor.getText()
      lib.process(editor.getText() (er files)) ->
        console.log 'All files ..'
        listFiles(files)

  listFiles: (files) ->
    for fileName in Object.keys(files)
      first = files[fileName].first
      second = files[fileName].second
      third = files[fileName].third
      console.log 'Done'

This is the javascript I'm trying to change to coffeescript inside convert() .. 这是我要在convert()更改为coffeescriptjavascript

lib.process(text, function (er, files) {
  console.log('All files ..');
  listFiles(files);
});

The line 线

lib.process(editor.getText() (er files)) ->

is not correct, since it's missing the commas needed to separate the parameters. 是不正确的,因为它缺少分隔参数所需的逗号。

When trying to transpile the line you wrote to JS it would look like this: 尝试转译您写给JS的行时,它看起来像这样:

lib.process(editor.getText()(er(files)))(function() {});

When trying to migrate JS to coffee, it's sometimes a good idea to start with http://js2.coffee/ and start from there. 尝试将JS迁移到咖啡时,从http://js2.coffee/开始并从那里开始有时是个好主意。 Always look at the transpiled JS result in order to check if everything will work as expected 始终查看转译的JS结果,以检查是否一切都能按预期工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM