Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.io/backbone/backbone-min.js"></script>
  
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <h1>Sample</h1>
  <div id="content"></div>
</body>
</html>
 
var SampleView = Backbone.View.extend({
  events: {
    "click" : '_clicked' 
  },
  
delegateEvents: function(events) {
      if (!(events || (events = _.result(this, 'events')))) return;
      this.undelegateEvents();
      for (var key in events) {
        var method = events[key];
        if (!_.isFunction(method)) method = this[events[key]];
        if (!method) throw new Error('Method "' + events[key] + '" does not exist');
        var match = key.match(/^(\S+)\s*(.*)$/);
        var eventName = match[1], selector = match[2];
        method = _.bind(method, this);
        eventName += '.delegateEvents' + this.cid;
        if (selector === '') {
           this.$el.on(eventName, method);
        } else {
           this.$el.on(eventName, selector, method);
        }
      }  
},
  
  render: function() {
    
     this.$el.html("hi");
     return this; 
  },
    
    _clicked: function() {
     alert("clicked!"); 
    }
});
$(function() {
  var view = new SampleView();
  $("#content").append(view.render().$el);  
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
wiredprairiepro
0viewers