Backbone.js サンプル1

<!DOCTYPE html>
<html lang="ja">



Backbone.js




Backbone.js




(function(){

 var UserModel = Backbone.Model.extend({
     defaults: {
         datetime: new Date().toISOString()
     },
     initialize: function(attrs, options) {
     }
 });

 var UserView = Backbone.View.extend({
     initialize: function(options) {
     },
     render: function() {
         $(this.$el).html(_.template($("#user_template").html(), this.model.attributes));
     }
 });

 var um = new UserModel({name: "TARO", age: 20});
 var uv = new UserView({el: $("#user"), model: um});

 uv.render();
}());