Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
566 views
in Technique[技术] by (71.8m points)

javascript - How to fix Uncaught TypeError: Cannot read property 'prototype' of undefined?

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()

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.enter image description here

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...