Backbone.js Events binding. Like “delegate” in Jquery?

后端 未结 2 1214
感情败类
感情败类 2020-12-15 11:14

I\'m new in backbone.js. And I see that in Backbone.js, the events binding :

var PersonView = Backbone.View.extend({
         


        
2条回答
  •  暖寄归人
    2020-12-15 12:10

    It isn't similar to delegate it does use delegate (unless the event doesn't have a selector). The event binding in Backbone looks like this:

    if (selector === '') {
      $(this.el).bind(eventName, method);
    } else {
      $(this.el).delegate(selector, eventName, method);
    }
    

    So it uses delegate on the view's element. That at least limits the events to elements within the view.

    You can't stop people from messing around with your elements and events in a debugger. They can change the HTML, the CSS, and even edit your JavaScript so you can't stop them from causing trouble on your page. You can stop them from making a mess on your server though, just don't trust anything that Backbone sends to your server and validate everything the same way you would validate anything else that comes in from the outside world.

    Basically, don't waste your time worrying about someone smashing their own face with a brick by messing with your HTML/events/JavaScript. Let them hurt themselves all they want. But do protect your server by not trusting anything from the outside world (and your servers shouldn't even trust themselves any more than they have to).

提交回复
热议问题