0

I'm trying to find my way through node.js and backbone.js. My intention is to share at least all model-states with the server and browser. Right now I'm not quite sure if I really need to share views as well. I also want to handle all routes by express and nodejs and not backbone. To keep my code a wee bit more structured I was looking forward to keep each model in a separate *.js file. By doing so I'm running into following error message:

TypeError: Object #<Object> has no method 'extend'

I thought it might be a problem with underscore missing in the separate file, so here is my basemodel:

models/BaseModel.js

var Backbone = require('../node_modules/backbone'),
_ = require('../node_modules/underscore'),

var BaseModel = Backbone.Model.extend({

  modelName: 'basemodel'

});

exports.BaseModel = BaseModel;

app.js var BaseModel = require('./models/BaseModel');

var MyModel = BaseModel.extend({
// ... attributes, functions etc.

});

Does anyone have a hint what I'm doing wrong there?

2
  • Read this question stackoverflow.com/questions/6549149/… Maybe it help? Commented Mar 6, 2013 at 17:27
  • Hey MrPovod, thanks for your reply. Not quite. I'm not even getting so far to work with attributes. If I place my BaseModel in app.js it works fine. Even if I output both BaseModel from BaseModel.js and BaseModel from app.js they seem both equal. Plus it DOES contain the extend function as well, but node.js complains about it. Commented Mar 6, 2013 at 17:42

2 Answers 2

1

Then try this code in app.js:

BaseModel = require('./models/BaseModel').BaseModel;

Or in models/BaseModel.js not of exports.BaseModel = BaseModel; use it - module.exports = BaseModel

Sign up to request clarification or add additional context in comments.

Comments

0

I actually figured it out. The flaw was in referencing to the BaseModel, so

this

var MyModel = BaseModel.extend({
  //
});

had to turn into:

var MyModel = BaseModel.BaseModel.extend({
   //
};

because of exports.BaseModel = BaseModel; in BaseModel.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.