$( "#foo" ).bind( "click", function() {this
alert( "User clicked on 'foo.'" );prototype
});
on的別名ip
var object = {};
_.extend(object, Backbone.Events);io
object.on("alert", function(msg) {
alert("Triggered " + msg);
});event
object.trigger("alert", "an event");function
object在extend Backbone.Events後得到bind和trigger自定義名稱的events的能力。
on的別名cli
bind
_.bind(function, object, *arguments) object
var func = function(greeting){ return greeting + ': ' + this.name };
func = _.bind(func, {name: 'moe'}, 'hi');
func();
=> 'hi: moe'bind
將function綁定到object,function調用時,this將指向object。co
bindAll _.bindAll(object, *methodNames)
用一系列的methodNames將methods綁定到object,function調用時將在object的上下文中。
Function.prototype.bind()
fun.bind(thisArg[, arg1[, arg2[, ...]]])
與其餘三種bind關係不大。