-
-
Save pavelpower/6808988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Backbone = require('backbone'); | |
var _ = require('underscore'); | |
var User = Backbone.Model.extend({ | |
// TODO: эту функцию вообще не надо писать, | |
// потому что конструктор такого же вида и так по дефолту создается | |
// при вызове функции Backbone.Model.extend | |
constructor: function() { | |
Backbone.Model.apply(this, arguments); | |
}, | |
validate: function(attrs, options) { | |
if ( !_.isString(attrs.name)) { | |
return "Имя должно быть строкой"; | |
} | |
if ( !_.isNumber(attrs.age) ) { | |
return "Возраст должен быть целочисленным выражением"; | |
} | |
if ( !_.isString(attrs.position) ) { | |
return ""; | |
} | |
}, | |
// описываешь методы, не забывай ствить заптые | |
// setName - ты же присваеваешь имя, что еще за attr.name? | |
setName: function(name) { | |
this.name = name; | |
}, | |
setAge: function(age) { | |
this.age = age; | |
}, | |
setPosition: function (position) { | |
this.position = position; | |
} | |
}); | |
module.exports = User; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment