|
Answer» We can write the methods which contain the business logic.
SEE the EXAMPLE below:
Person = Backbone.Model.extend({ DEFAULTS: { name: 'Fetus', age: 0, child: '' }, initialize: function(){ alert("This class has adop() method which contains business logic to set new child."); }, adopt: function( newChildsName ){ this.set({ child: newChildsName }); } }); VAR person = new Person({ name: "Thomas", age: 67, child: 'Ryan'}); person.adopt('John Resig'); var child = person.get("child"); // 'John Resig' We can write the methods which contain the business logic. See the example below: Person = Backbone.Model.extend({ defaults: { name: 'Fetus', age: 0, child: '' }, initialize: function(){ alert("This class has adop() method which contains business logic to set new child."); }, adopt: function( newChildsName ){ this.set({ child: newChildsName }); } }); var person = new Person({ name: "Thomas", age: 67, child: 'Ryan'}); person.adopt('John Resig'); var child = person.get("child"); // 'John Resig'
|