如何修复未捕获的类型错误:无法读取未定义的属性“原型"? [英] How to fix Uncaught TypeError: Cannot read property 'prototype' of undefined?

查看:19
本文介绍了如何修复未捕获的类型错误:无法读取未定义的属性“原型"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题.我正在使用backbone.js.我在示例中编写了此代码:

I have a little problem. I'm using backbone.js. I wrote this code like in example:

<script>
$(document).ready(function () {
    window.App = {
        Views: {},
        Models: {},
        Collections: {}
    }

    App.Collections.Users = Backbone.Collection.extend({
         model: App.Models.User,
         url: 'service'
    });
    App.Models.User = Backbone.Model.extend({});

    App.Views.App = Backbone.View.extend({
         initialize: function() {
             console.log( this.collection.toJSON() );
         }
    });

});
</script>

比我启动服务器并在浏览器控制台中输入:

Than I started server and in browser console type this:

var x =new App.Collections.Users();
x.fetch()

这会导致错误:Uncaught TypeError: Cannot read property 'prototype' of undefined.但是数据是作为响应存在的.详情见图片.如何解决这个问题?感谢您的回答.

And this follows to error: Uncaught TypeError: Cannot read property 'prototype' of undefined. But data is present in response. Details in picture. How to fix this? Thanks for you answers.

推荐答案

我修复了这个错误.问题是我创建了集合,然后是模型.集合使用用户模型作为工作单元,但是当我定义这个集合时,我并没有定义模型.

I fixed this bug. The problem was that I created Collection and then the Model. Collections use user model, as working unit, but when I defined this Collection, I did not define Model.

所以,如果你想避免这个错误,首先定义一个模型,然后再定义集合.

So, if you want to avoid this bug, firstly define a Model and only then define the Collection.

这篇关于如何修复未捕获的类型错误:无法读取未定义的属性“原型"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆