首页 > 解决方案 > backbone.js: Right-hand side of 'instanceof' is not an object

问题描述

I'm newer with jquery and backbone, hope someone could help me with this error. I have a web application that, sometimes, throws this error in the console

require.js:900 TypeError: Right-hand side of 'instanceof' is not an object
    at child.setElement (backbone.js?__nc__=1527837925799:1040)
    at child._ensureElement (backbone.js?__nc__=1527837925799:1102)
    at child.Backbone.View (backbone.js?__nc__=1527837925799:990)
    at child [as constructor] (backbone.js?__nc__=1527837925799:1545)
    at new child (backbone.js?__nc__=1527837925799:1545)
    at child.initialize (application.js?__nc__=1527837925799:357)
    at child.Inditex.Application (backbone-inditex-1.2.0.js?__nc__=1527837925799:27)
    at new child (backbone.js?__nc__=1527837925799:1545)
    at createApp (main.js:201)
at Object.execCb (require.js:1690)

If this error happens, with a reload of the webpage is fixed (sometimes with 3 or 4 times) but I can't know why this happens.

I have found the line where this error is thrown. In backbone.js file, the method setElement

setElement: function(element, delegate) {
      debugger;
      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;
    },

sometimes, Backbone.$ is not an object and is when the error hapens.

¿Any idea for resolving this error? I'm using backbone.js 1.1.0

Thanks in advance

标签: backbone.jsinstanceof

解决方案


就我而言,我可以修复它更改我的 main.js。错误是,在某些情况下,在加载 jquery 之前加载了主干。我的 main.js 是这样的

垫片:{'underscore':{出口:'_'},'backbone':{deps:['underscore'],出口:'Backbone'}

我必须在 jquery 的主干中添加一个 deps,就像这样

垫片:{'underscore':{出口:'_'},'backbone':{deps:['jquery','underscore'],出口:'Backbone'}


推荐阅读