Javascript Moustrap node.js;未捕获类型错误:回调不是函数
我最近开始使用electron创建一个应用程序来免费创作音乐。不幸的是,在尝试使用捕鼠器为其设置全局键盘快捷键时,我得到了错误Javascript Moustrap node.js;未捕获类型错误:回调不是函数,javascript,node.js,electron,mousetrap,Javascript,Node.js,Electron,Mousetrap,我最近开始使用electron创建一个应用程序来免费创作音乐。不幸的是,在尝试使用捕鼠器为其设置全局键盘快捷键时,我得到了错误uncaughttypeerror:callback不是一个函数。当我在electron上使用开发工具时,它表明问题与捕鼠器源代码有关,因此我不能100%确定错误在哪里,但是,我知道只有当其中一个捕鼠器键绑定被激活时才会出现错误。以下是我的代码: const { dialog } = require('electron').remote const ipc = requi
uncaughttypeerror:callback不是一个函数
。当我在electron上使用开发工具时,它表明问题与捕鼠器源代码有关,因此我不能100%确定错误在哪里,但是,我知道只有当其中一个捕鼠器键绑定被激活时才会出现错误。以下是我的代码:
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.
谢谢您的帮助我不确定这些参数在这里代表什么,但我认为应该是这样的:
Mousetrap.bind('x', newnote);
第二个参数应该是一个函数,但上面的方法是函数调用的结果,因此您会得到该错误。我不确定这些参数在这里表示什么,但我认为应该是这样的:
Mousetrap.bind('x', newnote);
第二个参数应该是一个函数,但是上面的方法是函数调用的结果,所以您得到了这个错误