简体   繁体   中英

TypeError: 'undefined' is not a constructor - Backbone Model

I have the following model:

lza.models.Location = Backbone.Model.extend({
    localStorage: new Backbone.LocalStorage("lzalocations")
});

And in another method that I call on clicking a button:

var p = new lza.models.Location();

In the console I see:

TypeError: 'undefined' is not a constructor (evaluating 'new lza.models.Location()')

These are in multiple javascript files, and I have made sure that the model.js file loads before the one that is trying to call it.

In my console I get the following:

lza                   #=> Object
lza.models            #=> Object
lza.models.Location   #=> undefined
lza.models.Location() #=> TypeError: 'undefined' is not a constructor (evaluating 'new lza.models.Location()')

So I know that the namespacing isn't the problem, but why is the Location object undefined, and why am I getting this error.

So the error was that the file that I downloaded for Backbone.localStorage was NOT a .js file, but actually a file that had the HTML of the page where I COULD download the .js file... Once I corrected it with the actual file, everything started working.

Thank you all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM