简体   繁体   English

Moustrap node.js; 未捕获的TypeError:回调不是函数

[英]Moustrap node.js; Uncaught TypeError: callback is not a function

I have recently started using electron to create an app to compose music on for free. 我最近开始使用电子来创建一个免费创作音乐的应用程序。 Unfortunately, while trying to set global keyboard shortcuts for it using mousetrap, I got the error Uncaught TypeError: callback is not a function . 不幸的是,在尝试使用捕鼠器为其设置全局键盘快捷键时,出现错误Uncaught TypeError: callback is not a function When I use developer tools on electron, it shows that the problem has something to do with the mousetrap source code, so I am not 100% sure where the error is, however, I do know that the error only appears when one of the mousetrap keybinds is activated. 当我在电子上使用开发人员工具时,它表明问题与捕鼠器源代码有关,因此我不能100%确定错误在哪里,但是,我知道该错误仅在其中一个捕鼠器中出现按键绑定已激活。 The following is my code: 以下是我的代码:

const { dialog } = require('electron').remote
const ipc = require('electron').ipcRenderer
const Vex = require('vexflow')
const Mousetrap = require('mousetrap');

//Global Variables
var keylist = {'z': 'a/4', 'x': 'b/4', 'c': 'c/4', 'v': 'd/4', 'b': 'e/4', 'n': 'f/4', 'm': 'g/4', 'a': 'a/5', 's': 'b/5', 'd': 'c/5', 'f': 'd/5', 'g': 'e/5', 'h': 'f/5', 'j': 'g/5', 'q': 'a/6', 'w': 'b/6', 'e': 'c/6', "r": 'd/6', 't': 'e/6', 'y': 'f/6', 'u': 'g/6'}
VF = Vex.Flow;

var canvas = document.getElementById("myCanvas");
var renderer = new Vex.Flow.Renderer(canvas, Vex.Flow.Renderer.Backends.CANVAS);     

// Use the renderer to give the dimensions to the SVG

// Expose the context of the renderer
var context = renderer.getContext();

// And give some style to our SVG
context.setFont("Arial", 10, "").setBackgroundFillStyle("#eed");


/**
 * Creating a new stave
 */
// Create a stave of width 400 at position x10, y40 on the SVG.
var stave = new VF.Stave(10, 40, 400);
// Add a clef and time signature.
stave.addClef("treble").addTimeSignature("4/4");
// Set the context of the stave our previous exposed context and execute the method draw !
stave.setContext(context).draw();

var chord = []
function newnote (e) {
    console.log('triggered')
    var code = (e.keyCode ? e.keyCode : e.which);
    //checks to see if the key is a shortcut, and isnt enter/return
    if (e in keylist && code !== 13) { 
        let note = keylist[e]
        chord.push(note)
    }
    //if the key is enter, then the chord is put no the staff and chord is cleared
    if (code == 13) {
        stave.VF.Formatter.FormatAndDraw(context, stave, notes);
         chord = []
    }
    else { }
}

Mousetrap.bind('x', newnote('x', stave, chord))
//etc.

Thank you for any help 感谢您的任何帮助

I'm not sure what these params represent here, but I think it should be something like this: 我不确定这些参数在这里代表什么,但是我认为应该是这样的:

Mousetrap.bind('x', newnote);

Second parameter should be a function, but the way you have it above is the result of the function call, so you're getting that error. 第二个参数应该是一个函数,但是上面得到它的方式是该函数调用的结果,因此您会遇到该错误。

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

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