Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Nodejs:在instanceof check中需要函数,但未定义_Javascript_Node.js_Node Webkit - Fatal编程技术网

Javascript Nodejs:在instanceof check中需要函数,但未定义

Javascript Nodejs:在instanceof check中需要函数,但未定义,javascript,node.js,node-webkit,Javascript,Node.js,Node Webkit,使用node webkit时出现此奇怪错误,下面是一个可以重新创建此错误的完整示例: index.js: var jQuery = require('jquery'); var Backbone = require('backbone'); (function($){ var ListView = Backbone.View.extend({ el: $('body'), initialize: function(){ _.bindAll(this, 'rend

使用node webkit时出现此奇怪错误,下面是一个可以重新创建此错误的完整示例:

index.js:

var jQuery = require('jquery');
var Backbone = require('backbone');

(function($){
  var ListView = Backbone.View.extend({
    el: $('body'),
    initialize: function(){
      _.bindAll(this, 'render');    
       this.render();
    },
    render: function(){
      $(this.el).append("<ul> <li>hello world</li> </ul>");
    }
  });
  var listView = new ListView();
})(jQuery);
看不清我的问题在哪里

大多数解决方案似乎都指向必须首先要求
jquery
,但我已经这样做了


我是一个相对的n00b,所以我希望我做了一些非常愚蠢的事情…

这是一个黑客行为,所以请注意,但是错误来自主干库中的此方法(
node\u modules/backbone/backbone.js:1046
,来自stacktrace):

通过在主干上显式设置jQuery,很可能可以避免此错误,如下所示:

var jQuery = require('jquery');
var Backbone = require('backbone');
Backbone.$ = jQuery;

这是一个完全未经测试的猜测,但它应该会起作用。

我想你不是在调用
instanceof
?查看导致问题的代码会很有帮助。如果它发生在后台,你能发布你的堆栈跟踪吗?@RobM。我已经编辑提供了一个完整的,最小的例子,给出了相同的行为,以及堆栈跟踪
TypeError: Expecting a function in instanceof check, but got undefined
at _.extend.setElement     (C:\SVN\mapthing\branches\mapthing_js\node_modules\backbone\backbone.js:1046:45)
at _.extend._ensureElement (C:\SVN\mapthing\branches\mapthing_js\node_modules\backbone\backbone.js:1108:14)
at Backbone.View (C:\SVN\mapthing\branches\mapthing_js\node_modules\backbone\backbone.js:1000:10)
at new child (C:\SVN\mapthing\branches\mapthing_js\node_modules\backbone\backbone.js:1566:41)
at file:///C:/SVN/mapthing/branches/mapthing_js/js/index.js:18:18
at file:///C:/SVN/mapthing/branches/mapthing_js/js/index.js:19:3
setElement: function(element, delegate) {
  if (this.$el) this.undelegateEvents();
  this.$el = element instanceof Backbone.$ ? element : Backbone.$(element);
  this.el = this.$el[0];
  if (delegate !== false) this.delegateEvents();
  return this;
},
var jQuery = require('jquery');
var Backbone = require('backbone');
Backbone.$ = jQuery;