Slide 39
Slide 39 text
var Presentation = (function(element){
var presentation = element;
presentation.delegate(".play", "click", play);
presentation.delegate(".stop", "click", stop);
function play(){
presentation.addClass(“playing”);
// ...
}
function stop(){
// ...
}
return {
play: playPresentation,
stop: stopPresentation
}
});
function(){
$(".presentation").delegate(".play", "click", play);
$(".presentation").delegate(".stop", "click", stop);
function play(){
$(this).parents(“.presentation:first”).addClass(“playing”);
// ...
}
function stop(){
// ...
}
}();
var Presentation = $.Class.create({
initialize: function(element) {
this._element = element;
this.play = element.find(“.play”);
this.stop = element.find(“.stop”);
this.play.bind(“click”, $.proxy(this.play, this));
this.stop.bind(“click”, $.proxy(this.stop, this));
},
play: function(){
this._element.addClass(“playing”);
// ...
},
stop: function(){
// ...
}
});
CLASS-BASED FUNCTION, CLOSURES EVENT-DRIVEN
39
Monday, March 28, 2011