Javascript-форум (https://javascript.ru/forum/)
-   Библиотеки/Тулкиты/Фреймворки (https://javascript.ru/forum/library-toolkit-framework/)
-   -   Ошибка. Backbone.js (https://javascript.ru/forum/library-toolkit-framework/33001-oshibka-backbone-js.html)

dixonich 07.11.2012 01:26

Ошибка. Backbone.js
 
Захотелось поизучать данный фреймворк. Пишу такой код в файле Model.js
И получаю вот такую ошибку (внизу)
Что это такое?
Person = Backbone.Model.extend({
    initialize: function(){
        alert("Welcome to this world");
    }
});

var person = new Person();

<!DOCTYPE html>

<html>
	<head>
		<script type="text/javascript" src = "backbone.js"></script>
		<script type="text/javascript" src = "Model.js"></script>
		<script type="text/javascript" src = "underscore.js"></script>
	</head>
	<body>

	</body>
</html>


Код:

Uncaught TypeError: Cannot call method 'extend' of undefined backbone.js:213
Uncaught TypeError: Object function (attributes, options) {
    var defaults;
    attributes || (attributes = {});
    if (options && options.parse) attributes = this.parse(attributes);
    if (defaults = getValue(this, 'defaults')) {
      attributes = _.extend({}, defaults, attributes);
    }
    if (options && options.collection) this.collection = options.collection;
    this.attributes = {};
    this._escapedAttributes = {};
    this.cid = _.uniqueId('c');
    this.changed = {};
    this._silent = {};
    this._pending = {};
    this.set(attributes, {silent: true});
    // Reset change tracking.
    this.changed = {};
    this._silent = {};
    this._pending = {};
    this._previousAttributes = _.clone(this.attributes);
    this.initialize.apply(this, arguments);
  } has no method 'extend'


Hoshinokoe 07.11.2012 05:58

dixonich,

Backbone жестко требует наличия underscore, иначе работать не будет. Перенесите подключение underscore.js в самое начало.

<!DOCTYPE html>

<html>
	<head>
		<script type="text/javascript" src = "underscore.js"></script>
		<script type="text/javascript" src = "backbone.js"></script>
		<script type="text/javascript" src = "Model.js"></script>
	</head>
	<body>

	</body>
</html>


Часовой пояс GMT +3, время: 05:04.