I'm learning some Backbone and I'm confused as to what this
is inside of the model.
Person = Backbone.Model.extend({
initialize: function() {
console.log('hello world');
this.bind("change:name", function() {
console.log(this.get('name') + " is now the value for name");
});
this.bind('invalid', function( model, error ) {
console.error(error);
});
},
defaults: {
name: "Bob Hope",
height: "unknown"
},
validate: function ( attributes ) {
if( attributes.name == 'Joe' ) {
return "Uh oh, you're name is Joe!";
}
}
});
var person = new Person();
person.set({name: "Joe", height:"6 feet"}, {validate:true});
console.log(person.toJSON());
What is going on in this.bind
? What is change:name
? Are initialize
and defaults
simply just methods inside of a javascript object?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…