> For the complete documentation index, see [llms.txt](https://javascriptuse.gitbook.io/javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascriptuse.gitbook.io/javascript/advanced/12.-learn-backbone.js-tutorial-from-scratch-for-beginners-part-12-model-events-in-backbone.js.md).

# 9. Learn backbone.js tutorial from scratch for beginners(Part 12) Model Events in backbone.js

![](https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M1E4Gk2ppVKb4olmnun%2F-MS3dEIKmtWvy1gCFSV1%2F-MS3dcRmvGhquGGkrayB%2FScreenshot_2.jpg?alt=media\&token=4aa6625b-88f0-4872-8a32-e00e8cd6f9e2)

![](https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M1E4Gk2ppVKb4olmnun%2F-MS3dEIKmtWvy1gCFSV1%2F-MS3ejG8l0nfAR6Jn6G_%2FScreenshot_3.jpg?alt=media\&token=df330eeb-9d6a-4612-97f6-7ba0ba83dd17)

C:\Users\Administrator\Desktop\gulp\app.js

```
jQuery(document).ready(function($) {
  var FirstModel = Backbone.Model.extend({
    initialize: function() {
      
    }
  });
  fmodel = new FirstModel();
  fmodel.set({
  	name: "<p>Tuong</p>",
  	author: "Lionel Pham"
  });
  var ModelView = Backbone.View.extend({
  	model: fmodel,
  	initialize: function() {
  		this.render();
  	},
  	render: function() {
  		console.log(this.model.escape("name"));
  		console.log(this.model.get("name"));
  		console.log(this.model.toJSON());
  	}
  });
  vmodel = new ModelView();
});
```

![](https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M1E4Gk2ppVKb4olmnun%2F-MS3dEIKmtWvy1gCFSV1%2F-MS3fppZPx6p5CzajySq%2FScreenshot_4.jpg?alt=media\&token=6ab5bf8e-c286-4b53-b14b-5abff20b9c11)

C:\Users\Administrator\Desktop\gulp\app.js

```
jQuery(document).ready(function($) {
  var FirstModel = Backbone.Model.extend({
    initialize: function() {
      
    }
  });
  fmodel = new FirstModel();
  fmodel.set({
  	name: "<p>Tuong</p>",
  	author: "Lionel Pham"
  });
  var ModelView = Backbone.View.extend({
  	model: fmodel,
  	initialize: function() {
  		this.render();
  	},
  	render: function() {
  		if(this.model.has("name")) {
  			console.log("Has key");
  		}else {
  			console.log("Has't key");
  		}
  		this.model.unset("name");
  		console.log(this.model.toJSON());
  	}
  });
  vmodel = new ModelView();
});
```

![](https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M1E4Gk2ppVKb4olmnun%2F-MS3dEIKmtWvy1gCFSV1%2F-MS3g74Omy2ePPY-_7ft%2FScreenshot_5.jpg?alt=media\&token=8f30f141-6421-4f27-a7fe-e2051116394c)

C:\Users\Administrator\Desktop\gulp\app.js

```
jQuery(document).ready(function($) {
  var FirstModel = Backbone.Model.extend({
    initialize: function() {
      
    }
  });
  fmodel = new FirstModel();
  fmodel.set({
  	name: "<p>Tuong</p>",
  	author: "Lionel Pham"
  });
  var ModelView = Backbone.View.extend({
  	model: fmodel,
  	initialize: function() {
  		this.render();
  	},
  	render: function() {
  		if(this.model.has("name")) {
  			console.log("Has key");
  		}else {
  			console.log("Has't key");
  		}
  		// this.model.unset("name");
  		this.model.clear("name");
  		console.log(this.model.toJSON());
  	}
  });
  vmodel = new ModelView();
});
```

![](https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M1E4Gk2ppVKb4olmnun%2F-MS3dEIKmtWvy1gCFSV1%2F-MS3hcOquu16tXB0tFYy%2FScreenshot_6.jpg?alt=media\&token=bb1b2a57-34d6-4e62-a436-e2ce440420ea)

```
jQuery(document).ready(function($) {
  var FirstModel = Backbone.Model.extend({
  	defaults: {
    	name: 'first',
    	author: 'Default Author', 
    },
    initialize: function() {
      
    }
  });
  fmodel = new FirstModel({
  	
  });
  fmodel.set({
  	name: "<p>Tuong</p>"
  });
  var ModelView = Backbone.View.extend({
  	model: fmodel,
  	initialize: function() {
  		this.render();
  	},
  	render: function() {
  		console.log(this.model.toJSON());
  	}
  });
  vmodel = new ModelView();
});
```
