Being the heart of any Javascript application, the models are known to be the most important building blocks for the creation of Javascript applications. The core of a JavaScript application is a Model. The data is retrieved and is populated by the model. A Model is a representation of a basic data object in the framework and is also a representation of the business entities with some business logic and business validations which is used for data storage and business logic. There are methods to modify the models in Backbone.JS. All the Backbone.JS Model’ methods are listed below:
METHOD | USES |
attributes | To define the property of a model. |
changed | To change all the attributes that have changed by using set() method. |
changedAttributes | To return the model’s attributes that have changed since the last set or becomes false, if there is no attribute. |
cid | To uniquely identify the model on the client. |
clear | To remove all attributes, which also includes the id attribute from a backbone model. |
clone | To create a deep copy of a model or to copy one model object to another object. |
defaults | To set a default value to a model. |
destroy | To destroy or remove the model from the server. |
escape | To get the html-escaped version of a model’s attributes. |
extend | To extend Backbone.model class while creating a backbone model. |
fetch | To accept the data from the server by delegating sync() method in the model. |
get | To get the value of an attribute in the model. |
has | To get a true value, if the attribute value is defined with a non-null value or non-undefined value. |
hasChanged | To return TRUE, if the attributes have changed since the last set. |
id | To identify model entity uniquely. |
idattribute | To specify the model’s unique identifier. |
initialize | To invoke the class’s constructor when model is created. |
isNew | To determine whether the model is a new or existing one. |
isValid | To checks the model state and to check validations for each attribute. |
parse | To return the model’s data by passing through the response object |
previous | To determine the previous value of the changed attribute. |
previousAttributes | To return state of the all attributes prior to last change event. |
save | To save the data of the model. |
set | To set the value of an attribute in the model. |
sync | To communicate with the server and to represent state of a model. |
toJSON | To get a copy of the attributes as an object for JSON stringification. |
unset | To remove an attribute from a backbone model. |
url | To return URL where model’s resource is located. |
urlRoot | To enable the URL function. |
validate | To validate the input before displaying the result. |
validationError | To display an error, if validation fails or after the invalid event is triggered. |