Backbone——常见错误

From:http://readystate4.com/2011/10/22/common-backbone-errors-and-what-they-mean/

by:ReadyState4

I’m a big fan of Backbone, the open-source JavaScript MVC framework. It’s lightweight, extendable, has an awesome event model that allows one to bind to changes from just about anything – it’s error messages, however, can be quite cryptic. Simply referencing a missing template file can lead to half an hour of wasted time tracking down the issue. Without further ado here’s a quick list of the day-to-day errors I occasionally encounter and what the problem ended up being:

TypeError: ‘undefined’ is not a function (evaluating ‘func.apply(obj, args.concat(slice.call(arguments)))’)

You probably created an event listener in view that binded to a function that doesn’t exist.

invalid ‘in’ operand attrs

You probably passed a string instead of an object to a Model.set. This frequently happens to me during an ajax callback using jQuery – for some reason Webkit browser return and object while Firefox returns a string.

Uncaught TypeError: Cannot call method ‘replace’ of null (underscore.js:768)

You’re calling an underscore template put not passing in the data it uses in the template. You’re referencing an underscore template that doesn’t exist. You could have created a new template but forgot to change it’s id.

TypeError: ‘undefined’ is not an object (evaluating ‘func.bind’)

You probably set a _bind or _bindAll in your view initiailize code and that method doesn’t exist in this view. Double check for a typo.

TypeError: ‘null’ is not an object (evaluating ‘func.bind’)

In your view you could be binding an event to a callback that got overwritten during initialization. Commen when your model is called “contact” and your model is called the same and gets passed in.

TypeError: ‘undefined’ is not a function (evaluating ‘this._configure(options || {})’) backbone.js #881

Something went wrong in the routing. You may have not instantiated a new view.

Uncaught TypeError: Cannot call method ‘extend’ of undefined (yourfile.js)

Your probably extending an object that extended a backbone object, but the reference to the object is wrong or missing.

Uncaught SyntaxError: Unexpected identifier (underscore.js:782)

Your template logic might have an error in it. Check that you closed open parens and such.

If you’ve experienced a Backbone error that’s not on the list, feel free to post it in the comments.

转载于:https://www.cnblogs.com/guancloud/archive/2013/01/20/2868311.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值