JavaScript ------------------------------------------------
var object = {}; _.extend(object, Backbone.Events); object.on("alert", function(msg) { alert("Triggered " + msg); }); object.trigger("alert", "an event");
CoffeeScript ------------------------------------------------
obj = _.extend {}, Backbone.Events obj.on 'alert', (msg)-> alert 'Triggered ' + msg obj.trigger 'alert', 'an event'
2 則留言:
新德老師,這邊的
_.extend(object, Backbone.Events);
也許可以試試看改用
obj = Backbone.Events.extend
看起來可能會漂亮一些 :)
Backbone.Events 沒有 extend 方法。
張貼留言